小编Lav*_*esh的帖子

静态块和变量

为什么在下面的代码中为可接受的静态变量赋值,但是使用相同的变量却不是?

class Test
{
static
{
   var=2;  //There is no error in this line
   System.out.println(var); //Why is there an error on this line if no error on the above     line
}
static int var;
}
Run Code Online (Sandbox Code Playgroud)

java

6
推荐指数
1
解决办法
113
查看次数

使用速记运算符进行类型转换

byte b=12;

b >>= 2; // Why is this legal? why does it automatically typecasts?

b = b >> 2; // Why is this illegal if the above is legal
Run Code Online (Sandbox Code Playgroud)

java

2
推荐指数
1
解决办法
259
查看次数

标签 统计

java ×2