在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Java中可以抛出任何可抛出的东西。
class YourBoss extends Throwable {
}
public class Main{
public void main(String[] s) throws YourBoss {
try{
throw new YourBoss();
}catch(Exception e){
}catch(Error e){
}
}
}
其他回答
Forth可以随时改变数字的基数:
HEX 10 DECIMAL 16 - .
0 Ok
它也不需要是预定义的:
36 BASE ! 1Z DECIMAL .
71 Ok
通知7。一个有效程序的例子:
Chomsky is a room. A thought is a kind of thing. Color is a kind of value. The colors are red, green and blue. A thought has a color. It is usually Green. A thought can be colorful or colorless. It is usually colorless. An idea is a thought in Chomsky with description "Colorless green ideas sleep furiously." A manner is a kind of thing. Furiously is a manner. Sleeping relates one thought to one manner. The verb to sleep (he sleeps, they sleep, he slept, it is slept, he is sleeping) implies the sleeping relation. Colorless green ideas sleep furiously.
像图灵机模拟器这样的其他愚蠢的东西可以找到。
反向波兰符号。这意味着实参在函数之前。换句话说,2加2就是2 +。
具有WTF特性的语言包括Forth、Postscript(是的,激光打印机的Postscript)和Factor。
JavaScript中的变量赋值可以创建全局变量。如果一个变量在函数中被赋值,并且没有在相同的作用域中声明为var,那么它将隐式声明为global。
function foo() {
x = "juhu"; // creates a global variable x!
var y = "kinners"
}
foo();
alert(x); // alerts "juhu"
alert(y); // alerts undefined
注意,var语句也可以在给变量赋值后使用:
function foo() {
x = 12;
var x; // x is now local
return x;
}
alert(foo()); // will alert 12;
alert(x); // will alert undefined
在Java中
byte b = 0;
b++;
等于
byte b = 0;
b = b + 1;
但事实并非如此。实际上,你会得到一个编译器错误,因为加法的结果是int类型的,因此不能赋值给字节变量b。当使用复合运算符时,编译器会自动在这里插入一个类型转换。所以
b++;
就变成了
b = (byte) b + 1;