我刚刚开始使用 Java,我需要一些帮助。我知道我不能对静态方法进行非静态引用,但我需要帮助来解决它。我正在阅读您可以通过创建对象的实例来访问非静态成员变量,但我不确定该怎么做。这是一些关于代码的。任何帮助或指示将不胜感激。
package tweetClassification;
public class PriorityRules {
public static void prioritize( final String userInput ){
ClassificationRule.apply( aUserInput ); //ERROR
// Cannot make a static reference to
// the non-static method apply(String)
// from the type ClassificationRule
}
}
*----------------------------------------------------------------
package tweetClassification;
public class ClassificationRule {
public void apply (final String aUserInput) {
apply( aUserInput );
}
}
*----------------------------------------------------------------
package tweetClassification;
import java.util.ArrayList;
public class RuleFirstOccrnc extends ClassificationRule {
public void apply ( final String aUserInput ){
for( TweetCat t: TwtClassif.tCat )
applyFirstOccurrenceRuleTo( t, aUserInput );
}
*----------------------------------------------------------------
package tweetClassification;
public class RuleOccrncCount extends ClassificationRule {
public void apply ( final String aUserInput ){
for( TweetCat t: TwtClassif.tCat )
applyOccurrenceCountRuleTo( t, aUserInput );
}