Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hide a constructor

 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks

I have a class Notification, which has two constructors and set of Notification Object Parameters



There is a class called NotificationManager, which has a method addNotification which takes in param as a Notification Object. i.e. public void addNotification(Notification notification). Here the Notification object is created using the first Constructor. Then i do some file writing. Notification and Notification manager are in the same package

Then i have a class NavNotificationManager which extends NotificationManager and there is a method in this where i use the second Notification Constructor and store the Notification objects in a list. NavNotificationManager is in a different package.

The issue is that when i do addNotification and pass in the Notification object. I do the following:-

Notification localNotification = new Notification(-----params----);
This option shows that is can take value for both the Notification constructors. I dont want do pass in the values for the second contructor. I tried to made second contuctor private but that does not work.

Can any one advice.

-Aditya



 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to advise without understanding the problem.

And your problem is: There are two constructors, and you don't want to use the second constructor? Then my advice would be to not use it. You still have the first constructor. Of course you have said you know that and already use it in some cases, which means I don't understand your problem.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:It's hard to advise without understanding the problem.

Indeed!
@Aditya:please explain clearly!
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The constructor that gets called will depend on what parameters you pass in (2 or 3 strings).

Do you mean that your IDE is showing you both options? I tried it in NetBeans, setting the second constructor to private, and it only shows me the first one, not both.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic