Tag: 匿名

如果将结果数组分配给变量,它是否为匿名数组

(我正在攻读Java助理考试OCJP 7) 一个问题要求选择非法初始化的例子。 其中一个答案是: – int [] k= new int[2]{5,10}; 解释说,在创建匿名数组时,指定数组的大小是非法的。 据我所知,这不是一个匿名数组,因为它被命名为“k”。 调用如下方法: – operateOnArray(new int[]{5,10}); 本来是一个匿名数组的例子,因为它没有被声明。 我可以看到“2”使其成为非法 – 但这并不是匿名的, 有人可以告诉我吗?

为什么java中的“超类型令牌”模式需要匿名类

在Neal Gafter的“超类型令牌”模式( http://gafter.blogspot.com/2006/12/super-type-tokens.html )中,使用匿名对象传递参数化类型: class ReferenceType{} /* anonymous subclass of “ReferenceType” */ ReferenceType<List> referenceType = new ReferenceType<List>(){ }; Type superClass = b.getClass().getGenericSuperclass(); System.out.println(“super type : ” + superClass); Type genericType = ((ParameterizedType)superClass).getActualTypeArguments()[0]; System.out.println(“actual parameterized type : ” + genericType); 然后结果是: super type : com.superluli.test.ReferenceType<java.util.List> actual parameterized type : java.util.List 我的问题是,匿名对象“referenceType”的作用是什么让它起作用? 如果我定义一个“ReferenceType”的显式子类并使用它而不是匿名样式,它就不会如预期的那样。 class ReferenceType{} class ReferenceTypeSub […]

匿名类如何有参数?

我不是一个java人,但我inheritance了一些我需要补丁的代码。 我将源代码转换为netbeans,我收到错误:匿名类实现接口; 不能有参数。 这是代码: Executor background = Executors.newSingleThreadExecutor(); Runnable mylookupThread = new Runnable(FilePath, SearchIndex) { public void run() { MainWindow.this.processFile(this.val$FilePath); Thread t = new Thread(new lookupThread(MainWindow.arrFile, true, false, this.val$SearchIndex)); t.setName(“Lookup”); t.setPriority(10); t.start(); } }; background.execute(mylookupThread); Executor statusThread = Executors.newSingleThreadExecutor(); Runnable myStatusThread = new Runnable() { public void run() { MainWindow.this.updateStatus(); } }; statusThread.execute(myStatusThread); 错误会在第二行弹出。 救命?!?

如何在NotSerializableException中标识匿名内部类

尝试在NetBeans中调试应用程序时收到以下错误消息: java.io.WriteAbortedException:写入已中止; java.io.NotSerializableException:board.Board $ 1 在调试过程中,我必须在许多类中插入“implements Serializable”,因为在从存储大对象的文件中读取过程中会出现exception。 这并不困难,因为exception消息中已经清楚了需要注意的类。 抛出我的是明显的匿名内部阶层’Board $ 1’。 我不能为我的生活找出造成问题的“董事会”来源。 我怎样才能做到这一点? 因为这是一个调试练习的问题,而不是代码的细节(我认为),我没有把它包括在内,但如果它有帮助我可以很容易地添加它。