jeudi 12 octobre 2017

final method / class with testing

given the very simple example:

public MyClass {

    final List<Integer> numbers = new ArrayList<>();

    public void method1() {
        ...
        addToNumbers(100);
        ...
    }

    boolean addToNumbers( Integer elem) {
        return numbers.add(elem);
    }
}

////////////////////////////////////////////////////

public MyClassTest() {

    @Test
    private void method1Test() {
        final MyClass x = new MyClass();
        ...
        //some mocking
        ...
        x.addToNumbers();
        ...
    }
}

If no inheritance is involved, does it make sense to declare the method addToNumbers() final? What about the test class? Does it make sense to declare it final as well?

Aucun commentaire:

Enregistrer un commentaire