I am struggling with a problem, which I can\'t understand why it doesn\'t work. How do I pass a variable through the double obj
and convert to int
You're in the top snippet, trying to assign a Double object to a primitive type like this.
double doubleObj=new Double( doublehelpermethod);
which would of course work because of unboxing (converting a wrapper type to it's equivalent primitive type) but what problem you're facing is dereferencing doublehelpermethod
.
doublehelpermethod.intValue()
is not possible because doublehelpermethod
is a primitive type variable and can not be associated using a dot .
See... AutoBoxing
The double
is a primitive type, while the Double
is a regular Java class. You cannot call a method on a primitive type. The intValue()
method is however available on the Double
, as shown in the javadoc
Some more reading on those primitive types can be found here