I am having the following problem -- I want to write a subclass of PrintWriter
that uses a downstream Writer object. The only way to provide that downstream
object is in the PrintWriter constructor, so I must provide it in my super()
constructor invocation. To do so, I must create it during that invocation.
But during that invocation I cannot store its value anywhere I can use (a local
variable would require an illegal access to "this").
(see example in workaround)
So to actually do this I need a method on PrintWriter that lets me get the
downstream Writer (or OutputStream) (if any). Without that, the workaround
is ugly and, in some cases, completely wrong as can expose an internal workhorse
object (the downstream writer) to the user of the PrintWriter subclass (or
at the least add a very odd construction mechanism).
Adding a getWriter and getOutputStream method would be far perferable to
either workaround.
I'm sure this applies to almost all of the streams that take downstream
streams.
that uses a downstream Writer object. The only way to provide that downstream
object is in the PrintWriter constructor, so I must provide it in my super()
constructor invocation. To do so, I must create it during that invocation.
But during that invocation I cannot store its value anywhere I can use (a local
variable would require an illegal access to "this").
(see example in workaround)
So to actually do this I need a method on PrintWriter that lets me get the
downstream Writer (or OutputStream) (if any). Without that, the workaround
is ugly and, in some cases, completely wrong as can expose an internal workhorse
object (the downstream writer) to the user of the PrintWriter subclass (or
at the least add a very odd construction mechanism).
Adding a getWriter and getOutputStream method would be far perferable to
either workaround.
I'm sure this applies to almost all of the streams that take downstream
streams.
- duplicates
-
JDK-4121985 java.io.PrintWriter: Make out a protected field
-
- Closed
-