我是 Java 新手。所以这个问题可能看起来很幼稚......但是你能帮忙吗?
例如,我有一个类如下:
public class Human {
private float height;
private float weight;
private float hairLength;
private HairState hairTooLong = new HairState() {
@Override
public void cut(Human paramHuman) {
Human.this.decreaseHairLength();
}
@Override
public void notCut(Human paramHuman) {
Human.this.increaseHairLength();
}
};
public float increaseHairLength () {
hairLength += 10;
}
public float decreaseHairLength () {
hairLength -= 10;
}
private static abstract interface HairState {
public abstract void cut(Human paramHuman);
public abstract void notCut(Human paramHuman);
}
}
然后我有另一个类如下:
public class Demo {
public static void main(String[] args) {
Human human1 = new Huamn();
Human.HairState.cut(human1);
}
}
该声明
Human.HairState.cut(human1);
是无效的...
我打算调用属于私有属性的公共函数。 cut()
hairTooLong
我该怎么做?