Example on how to use assertions in Java
This commit is contained in:
commit
a8d54ad54e
|
|
@ -0,0 +1,7 @@
|
|||
# Unwanted Eclipse IDE settings files:
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings/
|
||||
|
||||
# Unwanted build generated folders:
|
||||
/bin/
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# Assertions
|
||||
|
||||
Example on how to use assertions in Java
|
||||
|
||||
## Compile
|
||||
|
||||
`javac Assertions.java`
|
||||
|
||||
## Run
|
||||
|
||||
Assertions need to be enabled with `-ea` or `-enableassertions`
|
||||
|
||||
`java -ea Assertions`
|
||||
|
||||
or
|
||||
|
||||
`java -enableassertions Assertions`
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
public class Assertions
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
int a = 25;
|
||||
int b = 5 * 5;
|
||||
|
||||
assert a == b : "'a' and 'b' are not the same.";
|
||||
|
||||
String abc = "abc";
|
||||
String def = "def";
|
||||
|
||||
assert abc.equals(def) : "'abc' and 'def' are not the same.";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue