int does not override Integer in Java

后端 未结 6 921
春和景丽
春和景丽 2020-12-11 02:23

I had a function in Java with method signature

public void myMethod (int someInt, String someString) 

in my abstract class and I had over-

6条回答
  •  爱一瞬间的悲伤
    2020-12-11 03:16

    The reason the override doesn't work is because Integerand int are two different things. Integer is an object, whereas int is a primitive type. Java does the implicit typecasting for you. For example:

    int myInteger = new Integer(5);

    Will create a primitive int type called myInteger with a value of 5. As the Javadoc says,

    "The Integer class wraps a value of the primitive type int in an object."

提交回复
热议问题