在 CollectionData 中找不到 main 方法,请将 main 方法定义 as:main

Can't find the main method in the CollectionData, please will be the main method is defined as:main

package com.zs.container;
import java.util.ArrayList;
import com.java.array.generator.CountingGenerator.String;

import com.java.array.generator.CountingGenerator;
import com.java.array.generator.Generator;


public class CollectionData<T> extends ArrayList<T> {
    public CollectionData(Generator<T> gen, int quantity) {
        for (int i = 0; i < quantity; i++)
            add(gen.next());
    }
    // A generic convenience method:
    public static <T> CollectionData<T> list(Generator<T> gen, int quantity) {
        return new CollectionData<T>(gen, quantity);
    }
    public static void main(String[] args) {
        System.out.println("start");
        Generator<java.lang.String> gen =new CountingGenerator.String();
        ArrayList<java.lang.String> list=new CollectionData<java.lang.String>(gen,8);
        System.out.println(list);
    }
}

错误:class com. Zs。容器。在CollectionData中找不到main方法,请将main方法定义为: Public static void main (String [] args)

怎么了?我当然有主要方法!为什么会出错??

惊喜!当我删除这一行时 “导入 com.java.array.generator.CountingGenerator.String;” 效果很好!为什么???

the com.java.array.generator.CountingGenerator.String code:

package com.java.array.generator;

 public class CountingGenerator {

    static char[] chars = ("abcdefghijklmnopqrstuvwxyz"
            + "ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();

    public static class Character implements Generator<java.lang.Character> {
        int index = -1;

        public java.lang.Character next() {
            index = (index + 1) % chars.length;
            return chars[index];
        }
    }
    public static class String implements Generator<java.lang.String> {
        private int length = 7;
        Generator<java.lang.Character> cg = new Character();

        public String() {
        }

        public String(int length) {
            this.length = length;
        }

        public java.lang.String next() {
            char[] buf = new char[length];
            for (int i = 0; i < length; i++)
                buf[i] = cg.next();
            return new java.lang.String(buf);
        }
    }
} 

使用

public static void main(java.langString[] args)

为什么?因为 String 被解释为

import com.java.array.generator.CountingGenerator.String;