Java: How to limit access of a method to a specific class?

I would pass the object that is calling the method as an argument, i.e.

list.insert("x", this);

And then check if the passed Object is an Instance of Class A

 public void insert (String x, Object o)
   {
      if(o instanceof ClassA){
         /*insertion occurs*/
      }
   }

Leave a Comment