Java 内部类共享属性信息
我有一个叫做ContentStream的课程。。。问题是,内部类AddRectangle假设要获取类GraphicBeginn的getter的信息……我认为类ContentStream至少可以到达getter,因为getter是公共的。。。请告诉我怎么做Java 内部类共享属性信息,java,java-7,Java,Java 7,我有一个叫做ContentStream的课程。。。问题是,内部类AddRectangle假设要获取类GraphicBeginn的getter的信息……我认为类ContentStream至少可以到达getter,因为getter是公共的。。。请告诉我怎么做 public class ContentStreamExt extends ContentStreamProcessor { private Matrix graphicalMatrix; public ContentStreamPro
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
}
如果我正确理解了您的问题,add rectangle类应该被传递一个graphic begin实例,它可以在该实例上调用公共getter。这种连接可以由内容流类完成 顺便说一下,下面的句子在语法上是无效的
private static class AddRectangle(GrapicBeginn beginn)
您提供的代码有很多问题,正如另一张海报所指出的,它不能正确编译。看起来您在声明一个名为“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;
}
}
我已经实例化了GraphicBeginn的一个对象,因为我希望得到uUx和uUy,然后把它传递给AddRectangle(float x,float y)ok。。。但是内容流类无法读取GraphicBeginn类的getter,甚至无法读取它的public。您在哪里尝试这样做?enhanceAdditional方法中BeginGraphic实例上可用的方法有哪些?graphhicBegin填充uUx和uUy中只有一个私有方法。。。。在方法enhanceAdditional()中,我尝试…GraphicBeginn BeginGraphic=new GraphicBeginn();。。。float x=beginnGraphic.getuuux;float y=beginnGraphic.getuy;然后将其传递到AddRectangle(float x,float y)中,请更正问题中附带的代码;由于这个答案中突出显示的语法问题,它不会按原样编译。然后编写您希望实现的代码,用注释突出显示出现编译错误的部分。