Java claims control - best practices

I would like less computationally intensive statements to persist at all times and disable statements with higher computational load. A practical use case may be when we translate the code into production (according to the pragmatic programmer, this is the proposed method for processing statements).

What is the best way to control claims? (Note that I have already included statements in VM variables using "-ea").

A simple example:

/**
*
* @precondition sizeOfList >= 2
*/
private ArrayList<Integer> createSortedList(int sizeOfList){
    ArrayList<Integer> results = new ArrayList<Integer>();

    for(int i = 0; i<sizeOfList; i++){

        <algorithm to add sorted numbers to array>

    }

    if(<some_flag>)
        assert results.get(0) < results.get(1) : "Results are not sorted.";

    assert results.size() == sizeOfList : "Results-list size does not equal requested size.";

    return results;
}

Is it better to use System Properties to control a variable? If so, is it possible to set system properties for the entire project, and not just for a specific class (in Eclipse)?

Is it better to use a constant variable defined in the Constants class?

, ?

.

+5
1

assert , , , . , , - :

if (results.size() != sizeOfList)
    throw new AssertionError("Results-list size does not equal requested size.");

/ -ea JVM.

+2

All Articles