Why shortValue() method are concrete but intValue() is abstract into java.lang.Number?

前端 未结 3 1759
忘了有多久
忘了有多久 2021-01-18 10:33

I have read source code of java.lang.Number and I wondered why

  1. intValue()
  2. longValue()
  3. floatVa
3条回答
  •  逝去的感伤
    2021-01-18 11:29

    @Anirudh sir, Small confirmation as you said that byte and short method are consuming the lesser memory to store the value, but it is not the right way to perform an operations by taking the same variable.. Because the byte variable will return you the negative value.

    //As per (step-1)Integer is the wrapper class object which is stored with 100000 value above range of byte. But the memory usage is less compare to int memory consumstion or range. because the int range is up to 600000 or smthng. remaining is waste of memory(apart from 100000), so you said that the int value(100000) if we convert to byte like(step-2) the more usage of memory will get reduced. But the value get stored inside the "b" variable is negative value. So here we cannot perform any operation with the original value(100000). Please suggest me if i am in wrong thought.

    step-1:- Integer io=new Integer(100000);

    step-2:- byte b=io.byteValue();

提交回复
热议问题