jonprasetyo jonprasetyo - 1 year ago 82
Java Question

Java - How to view assert messages in Eclipse

I have just been looking into assert in Java and now I am trying to figure out how can we view the message if the assert was true in Eclipse. Code below:

public class TheAssertClass {

public TheAssertClass(){

int y = 5;
int x = 4;

assert (y > x): "y is too big. y = " + y;

public static void main(String[] args){
TheAssertClass go = new TheAssertClass();

System.out.println("The program ran");


The console only displays "The program ran". I am not exactly sure if I am using this correctly?


roj roj
Answer Source

You might not have enabled assertions at the JVM level (with the -ea switch). If you haven't, then this would explain the behaviour you are seeing. Try making the assertion false and see if anything appears on the console.

Also have a look at the following questions & answers for more detail: * See What does the "assert" keyword do?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download