Why is the java.util.Scanner class declared "final"?

I use the scanner class to read several similar files. I would like to expand it to make sure that they all use the same separator, and I can also add methods like skipUntilYouFind (String thisHere) that they are all valid for everyone.

I can make a utility class that contains them, or insert the scanner class as a variable inside another class, but this is more cumbersome.

I found some reasons to declare the final class, but why is this done here?

+5
source share
3 answers

, , , , . , , ( - ), , .

, :

public boolean nextBoolean()  {
    clearCaches();
    return Boolean.parseBoolean(next(boolPattern()));
}

, , "awesome" "true" ( - ). , super.nextBoolean(), , . super.nextBoolean(), clearCaches() , , . clearCaches(), . , , , , , , .

, , , ( , ).

+4

, . , - , , . , , , ( java.util.Scanner), . . , / script, ... .

+1

, , , .

, , . ( ) Scanner.

I saw many implementations that used inheritance to change behavior. The end result was usually a monolithic design, and in some cases a broken contract and / or violation of behavior.

0
source

All Articles