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?
java
add a comment |
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
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
add a comment |
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
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
java
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
Just use a normal import:
import suman.Output.foo.PUT.basic.req.Body;
public class FooImplementer {
public void bar(){
Body x = new Body();
}
}
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 saya.long.Body
andanother.long.Body
into two shorter names, not necessarily calledBody
. @AlexanderMills Java does not provide import aliasing, unfortunately.
– NPras
Nov 21 '18 at 3:25
|
show 8 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Just use a normal import:
import suman.Output.foo.PUT.basic.req.Body;
public class FooImplementer {
public void bar(){
Body x = new Body();
}
}
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 saya.long.Body
andanother.long.Body
into two shorter names, not necessarily calledBody
. @AlexanderMills Java does not provide import aliasing, unfortunately.
– NPras
Nov 21 '18 at 3:25
|
show 8 more comments
Just use a normal import:
import suman.Output.foo.PUT.basic.req.Body;
public class FooImplementer {
public void bar(){
Body x = new Body();
}
}
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 saya.long.Body
andanother.long.Body
into two shorter names, not necessarily calledBody
. @AlexanderMills Java does not provide import aliasing, unfortunately.
– NPras
Nov 21 '18 at 3:25
|
show 8 more comments
Just use a normal import:
import suman.Output.foo.PUT.basic.req.Body;
public class FooImplementer {
public void bar(){
Body x = new Body();
}
}
Just use a normal import:
import suman.Output.foo.PUT.basic.req.Body;
public class FooImplementer {
public void bar(){
Body x = new Body();
}
}
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 saya.long.Body
andanother.long.Body
into two shorter names, not necessarily calledBody
. @AlexanderMills Java does not provide import aliasing, unfortunately.
– NPras
Nov 21 '18 at 3:25
|
show 8 more comments
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 saya.long.Body
andanother.long.Body
into two shorter names, not necessarily calledBody
. @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
|
show 8 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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