Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (10.2k points)

In Java, it is perfectly legal to define final arguments in interface methods and do not obey that in the implementing class, e.g.:

public interface Foo {

    public void foo(int bar, final int baz);

}

public class FooImpl implements Foo {

    @Override

    public void foo(final int bar, int baz) {

        ...

    }

}

In the above example, bar and baz has the opposite final definitions in the class VS the interface.

In the same fashion, no final restrictions are enforced when one class method extends another, either abstract or not.

While final has some practical value inside the class method body, is there any point specifying final for interface method parameters?

1 Answer

0 votes
by (46k points)
edited by
Some IDEs will copy the signature of the abstract/interface method when inserting an implementing method in a sub class.

I don't believe it makes any difference to the compiler.

While I believe this was true in the past, I don't think current IDEs do this any more.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...