不使用IDE时 JAVA 注意点(使用低版本时需要注意Autoboxing and intern)

Java

  • Inner class cannot be overridden.
  • Name hiding in Java only happens for static method, while it also happens for instance methods in C++.
  • Arrays can be up-cast but not down-cast.
  • Class with different type parameter is not compatible. 
  • Method with wildcard type parameter as type of argument cannot be called. 
  • System.out.println(true ? Integer.valueOf(1) : Double.valueOf(2)); prints 1.0 because of static binding of overload. 

     Method overriding is determined with compile time type information. 

     Tertiary operator performs unboxing if both alternative are eligible. 

  • Generic array cannot be created, unless <?> which means nothing.
  • Autoboxing and intern: 

    -128 == new Integer(-128) is true due to unboxing and arithmetic equality. 

    new Integer(-128) == new Integer(-128) is false . 

    Integer.valueOf(-128) == Integer.valueOf(-128) is true due to guaranteed caching of -128 to 127 . 

    Integer.valueOf(128) == Integer.valueOf(128) is undefined. 

    Caching behavior of Long.valueOf() is also undefined. 

  • Calling System.exit(0) in try block can prevent finally block from execution.
  • Return value in try block can be overridden by another return in finally block, or the target object of the returned reference can be modified.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值