我正在Java中使用单一方法实现特定算法。这个算法需要一个不会在其他地方使用的数据结构,所以我认为适合使用本地类。算法的最后一步需要遍历方法中早先创建的所有对象,所以我认为我会让本地类的构造函数将新创建的对象添加到列表中。在Java中,本地类可以访问声明为final的局部变量。所以,我想是这样的: public void doThing() {
class Foo {
pu
在HelloWorldAnonymousClasses示例程序(from here): /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* mod
public class Main {
public static void main(String[] args) {
int b=1;
final int c=2;
String s1[] = new String[]{"A","B","C"};
class InnerMain{
int a=5;