• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing static variables-Help Please!!  RSS feed

 
Suat Ugurlu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a problem and if any of you can help me I would be very thankful.

I have several classes with the same name and serialized and kept
in the disk.

public class a {..}
public class a {..}
public class a {..}

In my program , I load this classes when I need.
That means there are different objects from the same class name (
but not from the same class in fact) in memory at the same time.
What I want to ask is that if I can access a public static variable defined in one of this classes from any of others.

suppose

public class a
{
public static String staticvariable ="This is the static variable";
..
}

public class a
{
//I want to access the staticvariable here..how?
}

I hope I could explain enough what I need.
In fact I am asking this for security reasons. Because I want to
prevent direct access to a class from others whose all names are the same.


Regards
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely all these classes must be in different packages. You can always use the fully qualified class name to access a variable:

com.mycompany.myapp.somepackage1.a.staticvariable
com.mycompany.myapp.somepackage2.a.staticvariable
 
Suat Ugurlu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thank you for your answer.
Then the only way of accessing the variable is to seperate
classes with packages since class names are the same,
Otherwise it is not possible, right?

Thanks..
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, as a Java developer, you can always avoid name space conflicts by your control of the names of the packages and classes. If there was only one package, you would need to have different names for your classes.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!