我有这行代码:
List<IObserver<?>> observers = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)
并得到以下 3 个错误:
Cannot instantiate the type ArrayList<?>
Syntax error on token "<", ? expected after this token
Type mismatch: cannot convert from ArrayList<?> to List<IObserver<?>>
Run Code Online (Sandbox Code Playgroud)
我使用的是 Eclipse 3.7,我安装了 JDK 7 update 5,并且项目设置为在构建路径中使用 JRE 系统库 [JavaSE1.7]。
传入IObserver<?>
右侧的编译很好,但我必须使用菱形运算符。
我认为这是一个配置问题,但我无法弄清楚我错过了什么。
我有一个GWT列表框,我需要按字母顺序对列表框的内容(字符串)进行排序.什么是解决这个问题的好方法?
我正在考虑使用Collection and Sort或使用Arrays.sort()然后用排序值填充列表框.这是一个正确的方法吗?
谢谢
我想知道运行JUnit3-Test或JUnit4-Test是否有区别.即使总运行时间只有5-10%的改进,在一个带夜间构建的大型项目中,这也很重要.
Subquestins是:
@annotation
JUnit4风格需要更长时间才能解决?如果可能,请回答参考.
如果我有一个被调用的变量value
,如果我想写它的getter,那将getvalue()
是getter的一个好名字.还是getValue()
更好?
有人告诉我,getter名称应该与变量名称匹配.
如何在 for 循环中返回值?例如,如果我有一个循环给我 3 个数字:1,2,3...我怎样才能返回最后一个数字的值(这里是 3)?
public class Cod {
public static void main(String[] args) {
exp();
}
public static int exp() {
int x=10;
for (int i=1; i<=3;i++) {
x=x*10;
int y=x/10;
System.out.println(y);
return y;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我们最近在Java 7上进行了升级,但之后我们的套件面临着奇怪的问题,它首先使用@After注释执行方法,然后使用@Test注释执行方法.任何帮助将不胜感激.提前致谢
编辑:这是评论中的代码:
public class TestClasse extends TestCase {
@Test public void testLogin(){ System.out.println("TestCase1"); }
@Test public void testLogout(){ System.out.println("TestCase2"); }
@After public void testGenerateReport(){ System.out.println("testCase3") }
}
Run Code Online (Sandbox Code Playgroud) 我从特定文件夹获取文件路径列表,但是当我尝试将其添加到我的可变列表中时,列表仍为空.
var filePath: MutableList<String>? = null
val path = File(getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).path, "BacFo Camera")
if (path.exists()) {
for(i in path.list().iterator()){
filePath?.add("" + path.toString() + "/" + i) //here i=file name
}
}
Run Code Online (Sandbox Code Playgroud)
在运行Debugger之后,值确实存在变量,i
但有些可变列表保持为空.我是Kotlin的新手,请帮助!!
如何尽可能优化此功能
public void r1(String st1, int[] ar1) {
String inox = "newsearch";
for (int j = 0; j < ar1.length; j++) {
if (st1.equals(inox) && ar1[j] * 2 > 20) {
Integer intx = new Integer(ar1[j]);
intx = intx * 2;
System.out.print(intx.toString());
}
}
}
Run Code Online (Sandbox Code Playgroud) public class College{
int year;
String name;
College(int year,String name){
year=year;
name=name;
}
public static void main(String[] args) {
College first=new College(1998,"BITS");
System.out.println("The year is:"+first.year);
System.out.println("The name is:"+first.name);
}
}
Run Code Online (Sandbox Code Playgroud)
我的输出是:年份是0
名字null
这怎么样?据我所知,该对象首先无法直接访问私有数据成员.
java ×9
eclipse ×2
junit ×2
android ×1
coding-style ×1
gwt ×1
junit3 ×1
junit4 ×1
kotlin ×1
listbox ×1
mutablelist ×1
optimization ×1
performance ×1