Alexander Mills
Alexander Mills

Reputation: 100000

Alias a Java class from nested namespaces

I have a Java class that is located here:

package suman;

public class Output {
 public static class foo {
   public static class PUT {
     public static interface basic {
       public static class req {
         public static class Body {   // namespaced class "Body"
           String foo = "bar";
           int bar = 5;
           boolean zoom = false;
         }
       }
     }

  }
}

I use it like so:

import static suman.Output.foo;

public class FooImplementer {

  public void bar(){
    foo.PUT.basic.req.Body x = new foo.PUT.basic.req.Body()
  }
}

However, that's a lot of characters, I am looking for a way to alias it somehow. The only way I can think of aliasing it, is to use a private class, something like this:

class Body extends foo.PUT.basic.req.Body {
     private JsonObject(){}
}

and I can use it like so:

   public void bar(){
       Body x = new Body()
    }

is there perhaps another way to do this?

Upvotes: 0

Views: 1485

Answers (1)

shmosel
shmosel

Reputation: 50716

Just use a normal import:

import suman.Output.foo.PUT.basic.req.Body;

public class FooImplementer {
    public void bar(){
        Body x = new Body();
    }
}

Upvotes: 4

Related Questions