Results 1 to 8 of 8
Thread: Equivalent of " void* " in JAVA
- 08-13-2010, 12:20 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 8
- Rep Power
- 0
- 08-13-2010, 12:44 PM #2
-
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.
- 08-13-2010, 01:05 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
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
- 08-13-2010, 01:17 PM #5
Member
- Join Date
- Aug 2010
- Posts
- 8
- Rep Power
- 0
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.
- 08-13-2010, 02:56 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
- 08-13-2010, 08:57 PM #7
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
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:
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.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; } }Ever seen a dog chase its tail? Now that's an infinite loop.
- 08-16-2010, 06:55 AM #8
Member
- Join Date
- Aug 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Equivalent of "char *" in JAVA
By ABHIJEEEEEEET in forum New To JavaReplies: 3Last Post: 08-11-2010, 11:37 AM -
Equivalent of "strtoul" in JAVA
By ABHIJEEEEEEET in forum New To JavaReplies: 5Last Post: 08-11-2010, 09:49 AM -
How can I solve "void cannot be dereferenced" error?
By fervent07 in forum New To JavaReplies: 2Last Post: 04-05-2010, 08:54 PM -
How can I prevent "found void but expected java.lang.String" ?
By trueblue in forum New To JavaReplies: 3Last Post: 05-21-2009, 03:48 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks