I have this code snippet
import java.util.ArrayList;
import java.util.List;
public class AssertTest {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
assert(list.add("test")); //<-- adds an element
System.out.println(list.size());
}
}
Output:
0
Why is the output list empty? How does assert behave here?
Thank you in advance!
You should enable assertion with -ea flag… such as;
Also using assertion is worst place for side effects..