This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hi, - Do no use assertions to validate arguments to a public method - Do use assertions to validate arguments to a private method
So far so good when it comes to appropiate use of assert, but what about the "in betweeners", default and protected. Are there any best-practice (official) mentioned somewhere about those two? I personally would say that protected should be classified as public since you as a programmer can not tell if a class will be sub-classed by a class in another package. When it comes to default access I guess it could be classified as a private method since I guess most commonly you have full control of the current package during development.
Does anyone have any experience about what could be the "correct" definition? Could protected and default be mentioned in the exam as to their "appropriateness" when it comes to argument validation?
I have not seen any offical mention of use of assertions in "default" or protected methods. I do not recall anything in the "Programming for Assertions" document. I tend to agree with your analysis above.
For SCJP I guess it will be always a choice from the two extreme cases: public or private.
Originally posted by Barry Gaunt: For SCJP I guess it will be always a choice from the two extreme cases: public or private.
Thanks Barry, then I will stick with my own "definition" for the other cases. Though, default may be debateble, but I guess thats exactly the reason for Sun not mentioning anything about them, it may be like telling someone where to put the brackets