+ Start a Discussion
Venky1219Venky1219 

How to share wrapper class object in different classes

Hi all,

 

I have two classes as follows

First one...

 

public class ClassOne{

 public class ConeWrapper{

   String s1 ;

   String s2 ;

 

}

 public static ConeWrapper classOneMethod(){

    ConeWrapper  wrapper = new ConeWrapper();

    wrapper.s1 =  'abc' ;

    wrapper.s2 = 'xyz' ;

   return wrapper;

  }

}

 

 Second one..

public class ClassTwo{

 

public class ConeWrapper{

   String s1 ;

   String s2 ;

 

}

  public void methodTwo(){

         ConeWrapper wrapper  = ClassOne.classOneMethod();

  }

}

 

Now when I try to run second class am getting following error 

 

Save error: Illegal assignment from ClassOne.ConeWrapper   to ClassTwo.ConeWrapper  

 

 

 

So please help me ,is there any other way to do this ? 

 

 

 

SarfarajSarfaraj

Hi

 

I am not sure what is your purpose. Please correct me if I am wrong. What I see here is, you are defining two inner classes with same name within two different outer classes. Now you want to refer to the inner class of one outer class from the other outer class. If this is your requirement then you need to write this,

 

ClassOne.ConeWrapper wrapper  = ClassOne.classOneMethod();