Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

java - How can I solve "Cannot access <ObjectName>" warning?

This is my ExamResult class

@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
public class ExamResult {
    int class1;
    int credit1;
    int class2;
    int credit2;
    int class3;
    int credit3;
    int class4;
    int credit4;
    int class5;
    int credit5;
    int class6;
    int credit6;
}

And this is my main class

    CalculateService calculate = new CalculateService();
    calculate.calculateSPA(examResult)); //I'm trying to do this

But I got this message. The code is runable this is a just warning.

Cannot access spa_calculation.ExamResult

spa_calculation.CalculateService 
public float calculateSPA(@NotNull spa_calculation.ExamResult examResult)
Inferred annotations:
@org.jetbrains.annotations.NotNull
  custom-tests.main

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the information that you've given, it looks like you're getting a warning related to the @FieldDefaults(level = AccessLevel.PRIVATE) annotation on the ExamResults class. This annotation causes all fields in the ExamResults class to become private by default. I would recommend removing the annotation and instead making the fields private yourself. The difference here is that your IDE likely does not support this annotation (it does not know the meaning of this annotation for field access), whereas it does support tagging your fields with private (e.g. private int class1;), resulting in more specific compile errors if this is indeed the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...