Java Modules: Have access to a access to an object but unable to create the object
Let's say I have 2 Modules.
One called "Receiver" and one called "Modifier".
In the Receiver module I have a package called "com.danii.Receiver", with a class called "DataReceiver". And I have another package in the Receiver module called "com.danii.Entities", with a class called "Data". The Receiver module currently only exports com.danii.Receiver.
The class DataReceiver, when I run a function in it, will create a new Data object, and send it back.
In my Modifier module, I have it set to require com.danii.Receiver, and I wish to receive some Data via DataReceiver. I try to do this, but no matter what I do I cannot read it because it doesn't have access to the Data class.
How can I have access to read the Data DataReceiver gives me, but still not able to create Data?
java module visibility instantiation
|
show 1 more comment
Let's say I have 2 Modules.
One called "Receiver" and one called "Modifier".
In the Receiver module I have a package called "com.danii.Receiver", with a class called "DataReceiver". And I have another package in the Receiver module called "com.danii.Entities", with a class called "Data". The Receiver module currently only exports com.danii.Receiver.
The class DataReceiver, when I run a function in it, will create a new Data object, and send it back.
In my Modifier module, I have it set to require com.danii.Receiver, and I wish to receive some Data via DataReceiver. I try to do this, but no matter what I do I cannot read it because it doesn't have access to the Data class.
How can I have access to read the Data DataReceiver gives me, but still not able to create Data?
java module visibility instantiation
Exporting is only half of the process. The Modifier module needs to declarerequires com.danii.Receiver;
in its module-info.java.
– VGR
Nov 11 '18 at 21:12
I've done that, I should probably clarify that, sorry @VGR.
– Danii
Nov 11 '18 at 21:15
Ah, I see now. You must export every package whose classes you wish to make accessible by other modules. So, you needexports com.danii.Entities;
in addition to exporting com.danii.Receiver.
– VGR
Nov 11 '18 at 21:23
@VGR Doing that would make Data instantiate-able. As I said I do not want the Modifier module to be able to create Data, only receive it.
– Danii
Nov 11 '18 at 21:30
I see. I thought you were asking why you could not instantiate Data, but you were actually asking how to prevent instantiation of Data by other modules. In that case, Ryan’s answer is correct (except that you should never preface an interface name with anI
).
– VGR
Nov 11 '18 at 21:34
|
show 1 more comment
Let's say I have 2 Modules.
One called "Receiver" and one called "Modifier".
In the Receiver module I have a package called "com.danii.Receiver", with a class called "DataReceiver". And I have another package in the Receiver module called "com.danii.Entities", with a class called "Data". The Receiver module currently only exports com.danii.Receiver.
The class DataReceiver, when I run a function in it, will create a new Data object, and send it back.
In my Modifier module, I have it set to require com.danii.Receiver, and I wish to receive some Data via DataReceiver. I try to do this, but no matter what I do I cannot read it because it doesn't have access to the Data class.
How can I have access to read the Data DataReceiver gives me, but still not able to create Data?
java module visibility instantiation
Let's say I have 2 Modules.
One called "Receiver" and one called "Modifier".
In the Receiver module I have a package called "com.danii.Receiver", with a class called "DataReceiver". And I have another package in the Receiver module called "com.danii.Entities", with a class called "Data". The Receiver module currently only exports com.danii.Receiver.
The class DataReceiver, when I run a function in it, will create a new Data object, and send it back.
In my Modifier module, I have it set to require com.danii.Receiver, and I wish to receive some Data via DataReceiver. I try to do this, but no matter what I do I cannot read it because it doesn't have access to the Data class.
How can I have access to read the Data DataReceiver gives me, but still not able to create Data?
java module visibility instantiation
java module visibility instantiation
edited Nov 11 '18 at 21:17
asked Nov 11 '18 at 21:03
Danii
84
84
Exporting is only half of the process. The Modifier module needs to declarerequires com.danii.Receiver;
in its module-info.java.
– VGR
Nov 11 '18 at 21:12
I've done that, I should probably clarify that, sorry @VGR.
– Danii
Nov 11 '18 at 21:15
Ah, I see now. You must export every package whose classes you wish to make accessible by other modules. So, you needexports com.danii.Entities;
in addition to exporting com.danii.Receiver.
– VGR
Nov 11 '18 at 21:23
@VGR Doing that would make Data instantiate-able. As I said I do not want the Modifier module to be able to create Data, only receive it.
– Danii
Nov 11 '18 at 21:30
I see. I thought you were asking why you could not instantiate Data, but you were actually asking how to prevent instantiation of Data by other modules. In that case, Ryan’s answer is correct (except that you should never preface an interface name with anI
).
– VGR
Nov 11 '18 at 21:34
|
show 1 more comment
Exporting is only half of the process. The Modifier module needs to declarerequires com.danii.Receiver;
in its module-info.java.
– VGR
Nov 11 '18 at 21:12
I've done that, I should probably clarify that, sorry @VGR.
– Danii
Nov 11 '18 at 21:15
Ah, I see now. You must export every package whose classes you wish to make accessible by other modules. So, you needexports com.danii.Entities;
in addition to exporting com.danii.Receiver.
– VGR
Nov 11 '18 at 21:23
@VGR Doing that would make Data instantiate-able. As I said I do not want the Modifier module to be able to create Data, only receive it.
– Danii
Nov 11 '18 at 21:30
I see. I thought you were asking why you could not instantiate Data, but you were actually asking how to prevent instantiation of Data by other modules. In that case, Ryan’s answer is correct (except that you should never preface an interface name with anI
).
– VGR
Nov 11 '18 at 21:34
Exporting is only half of the process. The Modifier module needs to declare
requires com.danii.Receiver;
in its module-info.java.– VGR
Nov 11 '18 at 21:12
Exporting is only half of the process. The Modifier module needs to declare
requires com.danii.Receiver;
in its module-info.java.– VGR
Nov 11 '18 at 21:12
I've done that, I should probably clarify that, sorry @VGR.
– Danii
Nov 11 '18 at 21:15
I've done that, I should probably clarify that, sorry @VGR.
– Danii
Nov 11 '18 at 21:15
Ah, I see now. You must export every package whose classes you wish to make accessible by other modules. So, you need
exports com.danii.Entities;
in addition to exporting com.danii.Receiver.– VGR
Nov 11 '18 at 21:23
Ah, I see now. You must export every package whose classes you wish to make accessible by other modules. So, you need
exports com.danii.Entities;
in addition to exporting com.danii.Receiver.– VGR
Nov 11 '18 at 21:23
@VGR Doing that would make Data instantiate-able. As I said I do not want the Modifier module to be able to create Data, only receive it.
– Danii
Nov 11 '18 at 21:30
@VGR Doing that would make Data instantiate-able. As I said I do not want the Modifier module to be able to create Data, only receive it.
– Danii
Nov 11 '18 at 21:30
I see. I thought you were asking why you could not instantiate Data, but you were actually asking how to prevent instantiation of Data by other modules. In that case, Ryan’s answer is correct (except that you should never preface an interface name with an
I
).– VGR
Nov 11 '18 at 21:34
I see. I thought you were asking why you could not instantiate Data, but you were actually asking how to prevent instantiation of Data by other modules. In that case, Ryan’s answer is correct (except that you should never preface an interface name with an
I
).– VGR
Nov 11 '18 at 21:34
|
show 1 more comment
1 Answer
1
active
oldest
votes
One option that would allow you to keep most aspects of your current structure would be to have another exported package with an interface implemented by Data (I'll call it IData for now). Then DataReceiver can return an IData object (implementation would still be via the Data class). IData could be in its own exported package or in the Receiver package that you are already exporting.
add a comment |
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%2f53253222%2fjava-modules-have-access-to-a-access-to-an-object-but-unable-to-create-the-obje%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
One option that would allow you to keep most aspects of your current structure would be to have another exported package with an interface implemented by Data (I'll call it IData for now). Then DataReceiver can return an IData object (implementation would still be via the Data class). IData could be in its own exported package or in the Receiver package that you are already exporting.
add a comment |
One option that would allow you to keep most aspects of your current structure would be to have another exported package with an interface implemented by Data (I'll call it IData for now). Then DataReceiver can return an IData object (implementation would still be via the Data class). IData could be in its own exported package or in the Receiver package that you are already exporting.
add a comment |
One option that would allow you to keep most aspects of your current structure would be to have another exported package with an interface implemented by Data (I'll call it IData for now). Then DataReceiver can return an IData object (implementation would still be via the Data class). IData could be in its own exported package or in the Receiver package that you are already exporting.
One option that would allow you to keep most aspects of your current structure would be to have another exported package with an interface implemented by Data (I'll call it IData for now). Then DataReceiver can return an IData object (implementation would still be via the Data class). IData could be in its own exported package or in the Receiver package that you are already exporting.
answered Nov 11 '18 at 21:21
Ryan Cogswell
1,466211
1,466211
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53253222%2fjava-modules-have-access-to-a-access-to-an-object-but-unable-to-create-the-obje%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
Exporting is only half of the process. The Modifier module needs to declare
requires com.danii.Receiver;
in its module-info.java.– VGR
Nov 11 '18 at 21:12
I've done that, I should probably clarify that, sorry @VGR.
– Danii
Nov 11 '18 at 21:15
Ah, I see now. You must export every package whose classes you wish to make accessible by other modules. So, you need
exports com.danii.Entities;
in addition to exporting com.danii.Receiver.– VGR
Nov 11 '18 at 21:23
@VGR Doing that would make Data instantiate-able. As I said I do not want the Modifier module to be able to create Data, only receive it.
– Danii
Nov 11 '18 at 21:30
I see. I thought you were asking why you could not instantiate Data, but you were actually asking how to prevent instantiation of Data by other modules. In that case, Ryan’s answer is correct (except that you should never preface an interface name with an
I
).– VGR
Nov 11 '18 at 21:34