在java中获取实例变量的类对象

时间:2015-09-18 08:58:31

标签: java

我有一个类Route,它有一个stop类型的实例变量(不同的类类型)。现在我有一个返回类型停止的函数。如何获取与此停止对象关联的路径对象

public class Route{
   Stop stopInstance;

   public Route(){
       stopInstance = new Stop();
   }
}

//Stop class in another file
public class Stop{   String name;

   public Stop(){
      name = " no name specified yet";
   }
}

//Some function in another class MainClass
class MainClass{
   Stop stop = func();
   //A function with return type Stop
   public Stop func(){
     Route route = new Route();
     return route.getStop();  
//Assume getter and setter functions for route class for stop variable
   }

// now I need to get the route object reference associated with the stop object reference I received from func(). 
}

我知道它可以通过Route类型的Stop类中的附加字段来解决,但还有其他方法吗?

0 个答案:

没有答案