gpt4 book ai didi

java - 枚举字符串对象中出现 "cannot be applied to..."错误

转载 作者:行者123 更新时间:2023-12-02 09:45:45 26 4
gpt4 key购买 nike

我已经研究并修复了格式,创建了 getter 和 setter 以及构造函数,但它仍然返回一个错误,指出我无法应用我的字符串对象。我为我的问题措辞方式道歉,但我不知道如何清楚地陈述我的问题,因为我不太了解它,也不知道如何很好地解释它。

public class Enum {

public enum DictionaryFields {
DistinctAdjective1("Distinct", "[adjective]", "Familiar. Worked in Java"),
DistinctAdjective2("Distinct", "[adjective]", "Unique. No duplicates. Clearly different or of different kind."),
DistinctAdverb("Distinct", "[adverb]", "Uniquely. Written \"distinctly\"."),
DistinctNoun1("Distinct", "[noun]", "A keyword in this assignment."),
DistinctNoun2("Distinct", "[noun]", "An advanced search option."),
PlaceholderAdjective("Placeholder", "[adjective]", "To be updated...");


}

private final String generalNote = "DICTIONARY 340 JAVA";
private String definition;
private String word;
private String partOfSpeech;

private DictionaryFields(String word, String partOfSpeech, String definition) {
this.word = word;
this.partOfSpeech = partOfSpeech;
this.definition = definition;
}

public String getWord() {
return word;
}

public void setWord {
this.word = word;
}

public String getPartOfSpeech() {
return partOfSpeech;
}

public void setPartOfSpeech() {
this.partOfSpeech = partOfSpeech;
}

public String getDefinition() {
return definition;
}

public void setDefinition(String definition) {
this.definition = definition;
}

}

最佳答案

您的代码存在一些语法问题。具体来说,您正在定义一个名为“Enum”的类,但您实际上应该定义一个枚举,例如:

public enum DictionaryFields {
DistinctAdjective1("Distinct", "[adjective]", "Familiar. Worked in Java"),
DistinctAdjective2("Distinct", "[adjective]", "Unique. No duplicates. Clearly different or of different kind."),
DistinctAdverb("Distinct", "[adverb]", "Uniquely. Written \"distinctly\"."),
DistinctNoun1("Distinct", "[noun]", "A keyword in this assignment."),
DistinctNoun2("Distinct", "[noun]", "An advanced search option."),
PlaceholderAdjective("Placeholder", "[adjective]", "To be updated...");



private final String generalNote = "DICTIONARY 340 JAVA";
private String definition;
private String word;
private String partOfSpeech;

private DictionaryFields(String word, String partOfSpeech, String definition) {
this.word = word;
this.partOfSpeech = partOfSpeech;
this.definition = definition;
}

public String getWord() {
return word;
}

public void setWord() {
this.word = word;
}

public String getPartOfSpeech() {
return partOfSpeech;
}

public void setPartOfSpeech() {
this.partOfSpeech = partOfSpeech;
}

public String getDefinition() {
return definition;
}

public void setDefinition(String definition) {
this.definition = definition;
}

}

您需要在“DictionaryFields”内定义构造函数。他们的设置方式是,您实际上是在为“Enum”类定义一个构造函数。

关于java - 枚举字符串对象中出现 "cannot be applied to..."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56675876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com