我有一个名为 ContentStream 的类...问题是内部类 AddRectancle 假设获取 getter 的信息类 GraphicBeginn ...我认为类 ContentStream 至少可以在getter公开时到达getter ...请告诉我如何
public class ContentStreamExt extends ContentStreamProcessor
{
private Matrix graphicalMatrix;
public ContentStreamProcessorExt(ExtListener extListener)
{
super(extListener);
}
private void enhanceAdditional()
{
GraphicBeginn beginnGraphic = new GraphicBeginn();
super.register("a", beginnGraphic);
super.register("b", new AddRectangle(beginnGraphic));
}
private static class AddRectangle(GrapicBeginn beginn)
{
// should get the info of uUx and uUy
}
private static class GraphicBeginn implements ContentOperator
{
private float uUx;
private float uUy;
public float getuUx()
{
return this.uUx;
}
public float getuUy()
{
return this.uUy;
}
..... // the input for uUx and uuy will be created in a method
}
答案 0 :(得分:1)
如果我理解你的问题,那么添加矩形类应该传递一个图形开始的实例,它可以调用公共的getter。这种连接可以通过内容流类完成。
顺便说一句,以下语法无效
private static class AddRectangle(GrapicBeginn beginn)
答案 1 :(得分:1)
您提供的代码存在许多问题,如另一张海报所述,它无法正确编译。您还提供了一个方法签名,同时还声明了一个名为“AddRectange”的类。这是一个类还是一个方法?你需要决定哪一个,它不能两者兼而有之。这是一个例子,我想一想你在一般意义上要做的事情:
public class SampleClass {
public SampleClass() {
}
private void sampleClassMethod() {
A a = new A();
a.acceptB(new B());
}
private class A {
public void acceptB(B bObject) {
System.out.println(bObject.memberVar1);
}
}
private class B {
private int memberVar1 = 5;
}
}