wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes exporting non-public type through api Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exporting non-public type through api" Watch "exporting non-public type through api" New topic
Author

exporting non-public type through api

Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
I'm not sure if this is a Java issue or a NetBeans one. I have the following class (it's not complete, I just started working on it) with a warning showing up next to the constructor.
The warning "exporting non-public type through api" shows up next to the constructor and disappears if I delete the "public" access specifier of the class or of the constructor.
What does the warning mean and how can I get rid of it?

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


This warning is a feature by the IDE used, Netbeans in your case.

You can remove this by editing the Workspace settings from Window > Properties and setting Warnings to the level you require, if I am not mistaken.

Cheers,
Raj.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37923
    
  22
What exactly was the warning?

And welcome to the Ranch
Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
Thank you for your quick reaction, Raj!
This means that my code is correct from this point of view - or am I wrong?
To ask this more clearly - have I made a mistake in my code to cause this warning?
Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
Thank you for your answer and welcoming me, Sheriff Campbell!
I've stated the warning in the thread title, namely "exporting non-public type through api".
I will edit my first post to make this clearer.
In the mean time I've noticed that the same warning shows up for every new public method that I write.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37923
    
  22
I think Raj Kamal is correct. Edit the warnings settings, because they are too stringent. A warning from an IDE is something to check; you can ignore the warnings if you wish.
Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
Issue solved: it turns out that the Piece class wasn't public, and this was what caused the warning.
Thank you for your time and attention!
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3574
    
  14

It happens when a class A's method b() returns formal type C and both A and b()'s visibility are higher than type C's.

This usually happens when A and b() are both public, and C is package private. It also happens when C is a protected or private internal class, and A is its enclosing class.

It's not an error, because if b() is public, classes outside the package can still use the method, and get a reference to the most specific supertype of C that is public.

You can always do this: Object c = a.b().

It's a warning though, because it usually indicates that you haven't thought about using your access modifiers consistently.
Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
Stephan van Hulst wrote:It happens when a class A's method b() returns formal type C and both A and b()'s visibility are higher than type C's.

This usually happens when A and b() are both public, and C is package private. It also happens when C is a protected or private internal class, and A is its enclosing class.

It's not an error, because if b() is public, classes outside the package can still use the method, and get a reference to the most specific supertype of C that is public.

You can always do this: Object c = a.b().

It's a warning though, because it usually indicates that you haven't thought about using your access modifiers consistently.


Makes perfect sense!

My class C was created automatically while designing class A, and the IDE didn't create it already with an access modifier. I usually manually creat all my classes, but not this time.

Thank you, Stephan, for your detailed explanation! I now understand better what happened.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Campbell Ritchie wrote:I think Raj Kamal is correct. Edit the warnings settings, because they are too stringent. A warning from an IDE is something to check; you can ignore the warnings if you wish.

But you shouldn't turn off warnings just because you don't like it. In this case the warning was quite valid, and could be perfectly prevented. I myself have turned most warnings on in Eclipse, including annoying ones like missing serial version UID fields.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37923
    
  22
Agree, Rob. I was mistaken there.
Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
Rob Spoor wrote:
But you shouldn't turn off warnings just because you don't like it. In this case the warning was quite valid, and could be perfectly prevented. I myself have turned most warnings on in Eclipse, including annoying ones like missing serial version UID fields.

This is what I also thought and the reason why I asked the question.
As a beginner, I'd rather get annoyed by warnings and learn the right way from the very beginning, instead of learning to write wrong code and then spend a lot more time and energy to un-learn that and learn the right way.
Thank you for your contribution, Rob!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exporting non-public type through api
 
Similar Threads
getter method and setter method
Polymorphism
inheritance problem
Very new and confused
Extend ArrayList?