Forums Register Login

Using Assertion

+Pie Number of slices to send: Send
Can assertion be enabled for multiple classes? I.e. If my application will access class A, B, and C which may or may not be in the same package and I want to enable assertion on class A and B, but not C. :roll:
+Pie Number of slices to send: Send
Yes. At runtime, when you invoke your application, just use the -ea:qualified.className syntax for each class that you want assertions turned on for.
See Enabling and Disabling Assertions
+Pie Number of slices to send: Send
Thank you very much, Cindy.
+Pie Number of slices to send: Send
And things get interesting when Class B
inherits from Class A and Class A has
assertions enabled, and Class B does not ( or
vice versa ).
--------------------------------------
Considering the Certified Java Programmer Exam?
Get JCertify!
http://www.enterprisedeveloper.com/jcertify
For exam 310-025 and 310-035
+Pie Number of slices to send: Send
Thank you David for pointing that out.
Another question. I read about assertion in the book, JDK 1.4 Tutorial by Gregory M Travis. He has an example where he does something like"java -ea kg0 MyProgram" to enable assertion for the package pkg0. He leaves out ... after pkg0 name and the result is that assertion is disabled. I tried that myself and found the same result and no complaint from JRE. Is this because it thinks that I try to enable assertion for a class name, pkg0? And since there's no such class, the enable does not have effect. And seems like, it doesn't check for existence of the class either.
Thanks a bunch.
+Pie Number of slices to send: Send
Yes. The "..." is the hint to the JVM that the name you gave it is a package name instead of a class name.
Don't you just LOVE the -ea:... option . "Just check stuff in THIS directory".
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 658 times.
Similar Threads
What to learn first for Java?
How to use Assertions in Java
Assertion Question
on assertions
Doubt in K&B SCJP 5: assert and boxing
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:55:19.