例如,如果你有
int a=2; int b=3;
ArrayList<Integer>integers=new ArrayList<Integer>();
integers.add(a); integers.add(b);
Run Code Online (Sandbox Code Playgroud)
和
String c="cow"; String d="deer";
ArrayList<String> strings= new ArrayList<String>();
strings.add(c); strings.add(d);
Run Code Online (Sandbox Code Playgroud)
他们会采取不同的记忆吗?任何帮助/答案都将受到高度赞赏,谢谢!
在C++中,这个表达式将被编译,并且在运行时将打印test:
if(!1 >= 0) cout<<"test";
Run Code Online (Sandbox Code Playgroud)
但在Java中,这将无法编译:
if(!1 >= 0) System.out.println("test");
Run Code Online (Sandbox Code Playgroud)
而是需要括号:
if(!(1>=0)) System.out.println("test");
Run Code Online (Sandbox Code Playgroud)
但是test不会打印,因为1 >= 0是真的,而NOT真的是假的.
那么为什么它test在C++中编译和打印出来,即使该语句是错误的,但不是在Java中?
谢谢你的帮助.
从Java 7开始,可以使用以下代码:
try{
...
}
catch(FileNotFoundException | SomeOtherException e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但是在方法中模拟语法不是:
public int test(int |double d){
...
}
Run Code Online (Sandbox Code Playgroud)
而这必须完成
public int test(int d){
...
}
public int test(double d){
...
}
Run Code Online (Sandbox Code Playgroud)
或这个:
public class Foo<E>{
...
public int test(E something){
...
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能在catch块中的方法中做更简单的事情?是什么让catch块不同,(除了捕获Exceptions和它是一个块的事实)?
谢谢你的帮助.