なぜ機能しないのか理解できない問題に苦しんでいます。double obj
変数を に渡し、に変換するにはどうすればよいint
ですか?
上部のコード スニペットでは機能しないのに、行の下の下部のコード スニペットでは機能するのはなぜですか?
唯一の違いは、追加の変数を追加しているようです。これもdouble
?として型付けされます。
//Converting double to int using helper
//This doesn't work- gets error message
//Cannot invoke intValue() on the primitive type double
double doublehelpermethod = 123.65;
double doubleObj = new Double( doublehelpermethod);
System.out.println("The double value is: "+ doublehelpermethod.intValue());
//--------------------------------------------------------------------------
//but this works! Why?
Double d = new Double(123.65);
System.out.println("The double object is: "+ doubleObj);