Java - 找不到构造函数?

标签 java

尝试编译时,我的代码无法编译:

package ch02.genericStringLogs;

public class DemoGenericLogs {
  public static void main(String[] args) {
    GenericLogInterface<Float> genFloatLog = new LinkedGenericLog<Float>();
    LLGenericNode<Float> node0 = new LLGenericNode<Float>(2.2);
    LLGenericNode<Float> node1 = new LLGenericNode<Float>(3.3);
    LLGenericNode<Float> node2 = new LLGenericNode<Float>(4.4);
    LLGenericNode<Float> node3 = new LLGenericNode<Float>(5.5);
    genFloatLog.insert(node0);
    genFloatLog.insert(node1);
    genFloatLog.insert(node2);
    genFloatLog.insert(node3);

    System.out.println(genFloatLog.size());
    System.out.println(genFloatLog.toString());
    genFloatLog.clear();
    System.out.println(genFloatLog.size());

    GenericLogInterface<String> genStringLog = new LinkedGenericLog<String>();
    LLGenericNode<String> string0 = new LLGenericNode<String>("one");
    LLGenericNode<String> string1 = new LLGenericNode<String>("two");
    LLGenericNode<String> string2 = new LLGenericNode<String>("three");
    LLGenericNode<String> string3 = new LLGenericNode<String>("four");

    System.out.println(genStringLog.size());
    System.out.println(genStringLog.toString());
    genStringLog.clear();
    System.out.println(genStringLog.size());
  }
}

我收到此错误:

Error:
    part1/ch02/genericStringLogs/DemoGenericLogs.java:5: cannot find symbol
    symbol  : constructor LinkedGenericLog()
    location: class ch02.genericStringLogs.LinkedGenericLog<java.lang.Float>

最佳答案

假设它与您的earlier question中的类别相同, LinkedGenericLog<T> 的唯一构造函数是这个吗:

public LinkedGenericLog(String name)

所以当你构造一个时,你需要传入一个名称。例如:

GenericLogInterface<Float> genFloatLog = new LinkedGenericLog<Float>("Some name");

如果您不想传递名称,则需要更改 LinkedGenericLog - 添加无参数构造函数。在这种情况下,您希望日志具有什么名称?

关于Java - 找不到构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15123975/

相关文章:

Java 8 时区转换

java - 使用 PreparedStatement.RETURN_GENERATED_KEYS 时出现 SQLException

java - 使两列在sqlite中唯一

java - 获取有关正则表达式验证的特定消息

java - 如何在jSTL jsp中调用方法

java - 使用 Jena API 进行基本 RDFS 推理

java - 如何以编程方式生成 hibernate POJO 类?

java - Java中的模运算,Android问题

java - HttpClient 4.3.1的org.apache.http.client.utils.URIBuilder中的 `removeQuery()`和 `clearParameters()`有什么区别?

java - 字符串数组内存不足错误