Answer the question
In order to leave comments, you need to log in
Is it possible to access private fields in JAVA?
All hello, the question is the following, there is such a class
class ImmutableUserAgent implements UserAgent {
private final String userAgentString;
private final ImmutableAgentField userAgentStringField;
private final Map<String, ImmutableAgentField> allFields;
private final List<String> availableFieldNamesSorted;
private final boolean hasSyntaxError;
private final boolean hasAmbiguity;
private final int ambiguityCount;
public ImmutableUserAgent(MutableUserAgent userAgent) {
userAgentString = userAgent.userAgentString;
hasSyntaxError = userAgent.hasSyntaxError;
hasAmbiguity = userAgent.hasAmbiguity;
ambiguityCount = userAgent.ambiguityCount;
userAgentStringField = new ImmutableAgentField(userAgentString, 0L, false, userAgentString);
Map<String, ImmutableAgentField> preparingAllFields = new LinkedHashMap<>(userAgent.allFields.size());
Map<String, ImmutableAgentField> preparingAllFields = new LinkedHashMap<>(userAgent.allFields.size());
Answer the question
In order to leave comments, you need to log in
Both classes (ImmutableUserAgent and MutableUserAgent) are nested in the UserAgent interface. And nested classes "see through each other".
For example, this also works:
public class C0 {
class C1 {
private String s;
class C3 {
private String s;
}
}
class C2 {
public C2(C1.C3 c3) {
System.out.println(c3.s);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question