Strange behaviour with Object.intValue()

前端 未结 2 863
遇见更好的自我
遇见更好的自我 2021-01-16 16:56

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

2条回答
  •  悲哀的现实
    2021-01-16 17:11

    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

提交回复
热议问题