Results 1 to 8 of 8
  1. #1
    ABHIJEEEEEEET is offline Member
    Join Date
    Aug 2010
    Posts
    8
    Rep Power
    0

    Default Equivalent of " void* " in JAVA

    Hi,
    I am new to JAVA. I want to know the Equivalent of " void* " in JAVA.

    Kind Regards,
    Abhijeet M.

  2. #2
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    Quote Originally Posted by ABHIJEEEEEEET View Post
    I want to know the Equivalent of " void* " in JAVA.
    Huh???:eek:
    I don't get it.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You need to understand C or C++ to get it, and since it's been a while since I've coded with either language, I'll pass on this one.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ABHIJEEEEEEET View Post
    Hi,
    I am new to JAVA. I want to know the Equivalent of " void* " in JAVA.

    Kind Regards,
    Abhijeet M.
    I bet you are trying to translate a piece of C or C++ code to Java; it won't work for void pointers (void*) because you can cast them to something else in the first two language but you don't even have explicit pointers in Java and no void pointers either. There is no equivalent; a Void reference might come conceptually close but you can'nt cast it to something else. Maybe an Object reference might be better; I'd say: forget about it. The other way around: there are lots of concepts in Java that don't have a C nor C++ equivalent.

    kind regards,

    Jos

  5. #5
    ABHIJEEEEEEET is offline Member
    Join Date
    Aug 2010
    Posts
    8
    Rep Power
    0

    Default

    Yeah, I am connverting it. Now, I am using Object as an equivalent for "void *" . I didn't stuck yet by doing it. But don't know about future problems.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ABHIJEEEEEEET View Post
    Yeah, I am connverting it. Now, I am using Object as an equivalent for "void *" . I didn't stuck yet by doing it. But don't know about future problems.
    Neither do us because we don't know your C (or C++) code nor have we seen your Java translation.

    kind regards,

    Jos

  7. #7
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    You're probably looking for an "everything" type, which is, as already stated in this thread, the Object type. A simple way of explaining this is probably a comparison method, like equals. You want your method to take any possible parameter, so it's reasonable to use an Object argument, like so:
    Java Code:
    public class MyClass {
      private int num;
      public MyClass(int num) {
        this.num = num;
      }
    
      public int getNum() {
        return num;
      }
    
      public boolean equals(Object o) {
        if(o instanceof MyClass) {
          MyClass c = (MyClass) o;
          return getNum() == c.getNum();
        }
        return false;
      }
    }
    First you check if the argument passed to the equals method is indeed of the MyClass type, and only then do you make the comparison.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  8. #8
    ABHIJEEEEEEET is offline Member
    Join Date
    Aug 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Equivalent of "char *" in JAVA
    By ABHIJEEEEEEET in forum New To Java
    Replies: 3
    Last Post: 08-11-2010, 11:37 AM
  2. Equivalent of "strtoul" in JAVA
    By ABHIJEEEEEEET in forum New To Java
    Replies: 5
    Last Post: 08-11-2010, 09:49 AM
  3. How can I solve "void cannot be dereferenced" error?
    By fervent07 in forum New To Java
    Replies: 2
    Last Post: 04-05-2010, 08:54 PM
  4. Replies: 3
    Last Post: 05-21-2009, 03:48 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •