answersLogoWhite

0

Suppose you assume that a number passed into a method (say, methodOne()) will never be negative. While testing and debugging, you want to validate your assumption, but you don't want to have to strip out print statements, runtime exception handlers, or if/else tests when you're done with development. But leaving any of those in is, at the least, a performance hit. Assertions to the rescue!

Assertions work quite simply. You always assert that something is true. If it is, no problem. Code keeps running. But if your assertion turns out to be wrong (false), then a AssertionError is thrown right then and there, so you can fix whatever logic flaw led to the problem. Assertions come in two flavors: really simple and simple, as follows: Really simple: private void doSomething() { assert (y > x); // more code assuming y is greater than x } Simple: private void doSomething() { assert (y > x): "y is " + y + " x is " + x; // more code assuming y is greater than x }

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What are the types of social research?

there are three types of social research. 1) According methods/ purpose. 2) According to use. 3) According to series time.


What are the types of communication methods?

types of communication methods?


What is the purpose of an exchange host?

The purpose of exchange hosting is a server system that enables the receiving and sending of emails, various types of interactive communications and sharing of critical business information online.


What methods can one use to locate a particular address?

There are many methods to locating a particular address in today's modern society. A few of the methods one could try are magazines, newspapers and the phone book. There are also many apps out for various types of modern phones.


Digital integrated circuit use various types of what to achieve their purpose of operation?

Transistors and electronic miniature components packaged into a small case.


Explain the various types of conflict?

various types of audit


What are the types and methods of pricing?

asfsdfdsfa


Describe the purpose and types of business and administration support?

Describe the purpose and types of business and support?


What is the purpose of the different Types of Speeches?

different types ofspeeches are made to suit the occassion and purpose.


What is versatile computer?

versatility of computer means that the computer is able to perform various types of functions or operations.


How many methods of liver transplantation are there?

There are three types of liver transplantation methods.


What are the different types of EIA methods?

The different types of Environmental Impact Assessment (EIA) methods include screening, scoping, baseline studies, impact prediction, mitigation measures, monitoring, and auditing. Each method serves a specific purpose in assessing the potential environmental impacts of a proposed project or development.