Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - IllegalAccessError: accessing a protected method

I have two classes.

Class A has protected method m(), a is an instance of A.

Class B is in the same package as class A.

I am trying to access a.m() but I am getting IllegalAccessError...

What's wrong?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

The compiler should catch errors like this. As you are apparently getting this at runtime, something odd has happened. Probably you have changed the source code but fully recompiled.

Another potential, but obscure, problem is loading the classes through different class loaders. Classes loaded from different class loaders will be in different packages even if the package name is the same (in the same way as classes with the same name loaded by different class loaders will be different classes).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...