Java 新功能

enum:

 

构造和接口

public interface B {public void B_B();}

public enum A implements B {

A_A(0),

A_B(0),

A_C(0);

 

private int num;

A(int num) {

this.num = num;

}

 

public void B_B(){}

}

 

value-specific:

public enum A {

A_A{ public void perform(int num) {out.println(num + "A_A")} },

A_B{ public void perform(int num) {out.println(num + "A_B")} },

A_C{ public void perform(int num) {out.println(num + "A_C")} };

 

public abstract void perform(int num);

}

 

 

boxing and unboxing:

 

1. This code will throw a NullPointerException:

Integer i = null;

int j = i;

2. 特定primitive一定会被box成immutable wapper对象:

true和false

byte值:-128—127的short和int

char:/u0000—/u007F

例如:

Integer i1 = 256;

Integer i2 = 256;

i1 == i2 为false.

Integer i1 = 100;

Integer i2 = 100;

i1 == i2 为true

3. ?操作符:

String s = "hello";

StringBuffer ss = new StringBuffer("world");

boolean mutable = true;

CharSequence cs = mutable ? s : ss;

?能返回两个操作数的交集类,任何两个对象都可以赋值给Object

4. method解析:

先使用没有boxing的但使用vararg的method匹配,再用有boxing但没有vararg的匹配,最后使用boxing和vararg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值