Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why FilterInputStream and FilterOutputStream have different access modifiers in their constructors?

Tags:

java

io

I just found that FilterInputStream(InputStream) has a different access modifier(protected) to that(public) of FilterOutputStream(OutputStream)

Is there any technical reason for this?

like image 931
Jin Kwon Avatar asked Oct 19 '22 03:10

Jin Kwon


1 Answers

That's a good spot. The designers made a few mistakes when defining the Java API, and this inconsistency seems to be one of them. There's no reason why you would want to instantiate a FilterOutputStream directly, so defining the constructor with protected visibility should be preferred.

Another question you might ask is why are these classes not abstract. There's no technical reason for it being this way, it's just how it was designed.

like image 163
Joni Avatar answered Oct 29 '22 17:10

Joni