doubleValue()

We know that doubleValue.public double doubleValue()Returns the double value of this Float object. My question is that if an object contains a pair of numbers.How can I use doubleValue() to retrieve them?Thanks
[245 byte] By [ardmorea] at [2007-11-26 18:03:20]
# 1
doubleValue() is a method in the Float class, you can't just use it on any object you want to.
CaptainMorgan08a at 2007-7-9 5:33:29 > top of Java-index,Java Essentials,New To Java...
# 2
So, is there any way to get the pair values of an object?
ardmorea at 2007-7-9 5:33:29 > top of Java-index,Java Essentials,New To Java...
# 3
> So, is there any way to get the pair values of an> object?Yes. If they are public you can access them directly; otherwise, you need to put some getter methods in your class.
CaptainMorgan08a at 2007-7-9 5:33:29 > top of Java-index,Java Essentials,New To Java...
# 4

Would you please look at my code?

public class Data

{

public double x;

public double y;

public Data(double x,double y)

{

this.x=x;

this.y=y;

}

public String toString()

{

return String.format(" %.2f %.2f\n", x,y);

}

}

We insert these pair numbers into a linked list, then remove them.

Object removeObject = list1.removeFromFront();

Double d = (Double)removeObject.x;

Here a warn alert:

cannot find symbol x

Thanks

ardmorea at 2007-7-9 5:33:29 > top of Java-index,Java Essentials,New To Java...
# 5
removeObject is declared as an Object. Objects don't have an x andhence the error.If you are sure list1 will return a Data then cast removeObject.
pbrockway2a at 2007-7-9 5:33:29 > top of Java-index,Java Essentials,New To Java...
# 6
removeObject is a reference to Object. Object does not have a field x.Data has x((Data)removeObject).x
jverda at 2007-7-9 5:33:29 > top of Java-index,Java Essentials,New To Java...
# 7

ardy,

the above replies are spot on for a fix to the immediate problem... but if you're on java 1.6 or even 1.5 then you really need to bone up on collections and generics.

Start with [url=http://72.5.124.55/docs/books/tutorial/collections/index.html]Sun's java tut' on collections[/url], and the javaworld one is also worth the time.

It'll probably take you a couple of evenings to get through it.... but it'll save you days, weeks, and months of future headaches.

I'm a huge fan of generics.

keith.

corlettka at 2007-7-9 5:33:29 > top of Java-index,Java Essentials,New To Java...