Alias a Java class from nested namespaces












2















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?










share|improve this question




















  • 5





    If your actual model require such many nested class, change your model ;)

    – azro
    Nov 20 '18 at 23:42











  • Just import the class and use its simple name. import suman.Output.foo.PUT.basic.req.Body;...Body x = new Body();

    – Sotirios Delimanolis
    Nov 20 '18 at 23:47











  • @azro I wish, but this one file has many types in it, so a lot of nested things in one file

    – Alexander Mills
    Nov 20 '18 at 23:55
















2















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?










share|improve this question




















  • 5





    If your actual model require such many nested class, change your model ;)

    – azro
    Nov 20 '18 at 23:42











  • Just import the class and use its simple name. import suman.Output.foo.PUT.basic.req.Body;...Body x = new Body();

    – Sotirios Delimanolis
    Nov 20 '18 at 23:47











  • @azro I wish, but this one file has many types in it, so a lot of nested things in one file

    – Alexander Mills
    Nov 20 '18 at 23:55














2












2








2


1






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?










share|improve this question
















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?







java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 23:47









shmosel

36.2k43892




36.2k43892










asked Nov 20 '18 at 23:41









Alexander MillsAlexander Mills

18.7k32154316




18.7k32154316








  • 5





    If your actual model require such many nested class, change your model ;)

    – azro
    Nov 20 '18 at 23:42











  • Just import the class and use its simple name. import suman.Output.foo.PUT.basic.req.Body;...Body x = new Body();

    – Sotirios Delimanolis
    Nov 20 '18 at 23:47











  • @azro I wish, but this one file has many types in it, so a lot of nested things in one file

    – Alexander Mills
    Nov 20 '18 at 23:55














  • 5





    If your actual model require such many nested class, change your model ;)

    – azro
    Nov 20 '18 at 23:42











  • Just import the class and use its simple name. import suman.Output.foo.PUT.basic.req.Body;...Body x = new Body();

    – Sotirios Delimanolis
    Nov 20 '18 at 23:47











  • @azro I wish, but this one file has many types in it, so a lot of nested things in one file

    – Alexander Mills
    Nov 20 '18 at 23:55








5




5





If your actual model require such many nested class, change your model ;)

– azro
Nov 20 '18 at 23:42





If your actual model require such many nested class, change your model ;)

– azro
Nov 20 '18 at 23:42













Just import the class and use its simple name. import suman.Output.foo.PUT.basic.req.Body;...Body x = new Body();

– Sotirios Delimanolis
Nov 20 '18 at 23:47





Just import the class and use its simple name. import suman.Output.foo.PUT.basic.req.Body;...Body x = new Body();

– Sotirios Delimanolis
Nov 20 '18 at 23:47













@azro I wish, but this one file has many types in it, so a lot of nested things in one file

– Alexander Mills
Nov 20 '18 at 23:55





@azro I wish, but this one file has many types in it, so a lot of nested things in one file

– Alexander Mills
Nov 20 '18 at 23:55












1 Answer
1






active

oldest

votes


















5














Just use a normal import:



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

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





share|improve this answer





















  • 1





    ..............?

    – shmosel
    Nov 20 '18 at 23:52






  • 3





    No, that's not how static imports work.

    – shmosel
    Nov 20 '18 at 23:53






  • 2





    @AlexanderMills This has nothing to do with static imports. Static imports are for importing static members of another class so you don't have to prefix them with the class name.

    – shmosel
    Nov 20 '18 at 23:59








  • 1





    @AlexanderMills Then how would extending it help?

    – shmosel
    Nov 21 '18 at 1:04






  • 1





    I think his idea of extending would allow for aliasing say a.long.Body and another.long.Body into two shorter names, not necessarily called Body. @AlexanderMills Java does not provide import aliasing, unfortunately.

    – NPras
    Nov 21 '18 at 3:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403258%2falias-a-java-class-from-nested-namespaces%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Just use a normal import:



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

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





share|improve this answer





















  • 1





    ..............?

    – shmosel
    Nov 20 '18 at 23:52






  • 3





    No, that's not how static imports work.

    – shmosel
    Nov 20 '18 at 23:53






  • 2





    @AlexanderMills This has nothing to do with static imports. Static imports are for importing static members of another class so you don't have to prefix them with the class name.

    – shmosel
    Nov 20 '18 at 23:59








  • 1





    @AlexanderMills Then how would extending it help?

    – shmosel
    Nov 21 '18 at 1:04






  • 1





    I think his idea of extending would allow for aliasing say a.long.Body and another.long.Body into two shorter names, not necessarily called Body. @AlexanderMills Java does not provide import aliasing, unfortunately.

    – NPras
    Nov 21 '18 at 3:25
















5














Just use a normal import:



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

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





share|improve this answer





















  • 1





    ..............?

    – shmosel
    Nov 20 '18 at 23:52






  • 3





    No, that's not how static imports work.

    – shmosel
    Nov 20 '18 at 23:53






  • 2





    @AlexanderMills This has nothing to do with static imports. Static imports are for importing static members of another class so you don't have to prefix them with the class name.

    – shmosel
    Nov 20 '18 at 23:59








  • 1





    @AlexanderMills Then how would extending it help?

    – shmosel
    Nov 21 '18 at 1:04






  • 1





    I think his idea of extending would allow for aliasing say a.long.Body and another.long.Body into two shorter names, not necessarily called Body. @AlexanderMills Java does not provide import aliasing, unfortunately.

    – NPras
    Nov 21 '18 at 3:25














5












5








5







Just use a normal import:



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

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





share|improve this answer















Just use a normal import:



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

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






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 0:00









ghulam sarwar

31




31










answered Nov 20 '18 at 23:47









shmoselshmosel

36.2k43892




36.2k43892








  • 1





    ..............?

    – shmosel
    Nov 20 '18 at 23:52






  • 3





    No, that's not how static imports work.

    – shmosel
    Nov 20 '18 at 23:53






  • 2





    @AlexanderMills This has nothing to do with static imports. Static imports are for importing static members of another class so you don't have to prefix them with the class name.

    – shmosel
    Nov 20 '18 at 23:59








  • 1





    @AlexanderMills Then how would extending it help?

    – shmosel
    Nov 21 '18 at 1:04






  • 1





    I think his idea of extending would allow for aliasing say a.long.Body and another.long.Body into two shorter names, not necessarily called Body. @AlexanderMills Java does not provide import aliasing, unfortunately.

    – NPras
    Nov 21 '18 at 3:25














  • 1





    ..............?

    – shmosel
    Nov 20 '18 at 23:52






  • 3





    No, that's not how static imports work.

    – shmosel
    Nov 20 '18 at 23:53






  • 2





    @AlexanderMills This has nothing to do with static imports. Static imports are for importing static members of another class so you don't have to prefix them with the class name.

    – shmosel
    Nov 20 '18 at 23:59








  • 1





    @AlexanderMills Then how would extending it help?

    – shmosel
    Nov 21 '18 at 1:04






  • 1





    I think his idea of extending would allow for aliasing say a.long.Body and another.long.Body into two shorter names, not necessarily called Body. @AlexanderMills Java does not provide import aliasing, unfortunately.

    – NPras
    Nov 21 '18 at 3:25








1




1





..............?

– shmosel
Nov 20 '18 at 23:52





..............?

– shmosel
Nov 20 '18 at 23:52




3




3





No, that's not how static imports work.

– shmosel
Nov 20 '18 at 23:53





No, that's not how static imports work.

– shmosel
Nov 20 '18 at 23:53




2




2





@AlexanderMills This has nothing to do with static imports. Static imports are for importing static members of another class so you don't have to prefix them with the class name.

– shmosel
Nov 20 '18 at 23:59







@AlexanderMills This has nothing to do with static imports. Static imports are for importing static members of another class so you don't have to prefix them with the class name.

– shmosel
Nov 20 '18 at 23:59






1




1





@AlexanderMills Then how would extending it help?

– shmosel
Nov 21 '18 at 1:04





@AlexanderMills Then how would extending it help?

– shmosel
Nov 21 '18 at 1:04




1




1





I think his idea of extending would allow for aliasing say a.long.Body and another.long.Body into two shorter names, not necessarily called Body. @AlexanderMills Java does not provide import aliasing, unfortunately.

– NPras
Nov 21 '18 at 3:25





I think his idea of extending would allow for aliasing say a.long.Body and another.long.Body into two shorter names, not necessarily called Body. @AlexanderMills Java does not provide import aliasing, unfortunately.

– NPras
Nov 21 '18 at 3:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403258%2falias-a-java-class-from-nested-namespaces%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith