Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39713
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: how to add a method specific to builder of specific type only |
| Date | 2021-11-26 13:09 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <snr7sk$rgk$1@dont-email.me> (permalink) |
| References | <1b45ddda-a26e-467f-9cfe-0b0d7649a42bn@googlegroups.com> |
On 11/26/2021 9:15 AM, mike wrote:
>
> I want to add a method that is specific to DeleteSubtreeBuilder .
>
> SubtreeBuilders.createDeleteSubtree().appendOperation(OperType.DELETE)
>
> I just cannot seem to be able to add:
>
> appendOperation(OperType type) so it only appears in the DeteleSubtreeBuilder that SubtreeBuilders.createDeleteSubtree() returns.
Since createDeleteSubtree() returns a SubtreeBuilder reference, the
only methods callable through that reference are those belonging to (or
inherited by) the SubtreeBuilder class. Even if the actual instance
returned happens to be a subclass with additional methods, you cannot
use a SubtreeBuilder reference to call them.
I'm not entirely sure what to suggest, since I'm not entirely sure
I understand what you're trying to do. One likely possibility, though,
is to change createDeleteSubtree() to return a DeleteSubtreeBuilder
instead of a "vanilla" SubtreeBuilder (assuming DeleteSubtreeBuilder
is a subclass of SubtreeBuilder, which isn't actually spelled out in
the code provided). If the class relationships aren't as I assume, I'm
afraid I don't know how to help.
> public final class SubtreeBuilders {
>
> public static SubtreeBuilder<DeleteSubtree> createDeleteSubtree() {
> return new DeleteSubtreeBuilder();
> }
>
>
> public static SubtreeBuilder<SetSubtree> createSetSubtree() {
> return new SetSubtreeBuilder();
> }
>
> static class DeleteSubtreeBuilder extends AbstractSubtreeBuilder<DeleteSubtree>{
(I'm guessing AbstractSubtreeBuilder is a subclass of SubtreeBuilder
or implements a SubtreeBuilder interface, but I can't be sure.)
>
> @Override
> protected DeleteSubtree internalBuild() {
> return new DeleteSubtreeImpl(this);
> }
>
> }
>
> }
--
esosman@comcast-dot-net.invalid
Look on my code, ye Hackers, and guffaw!
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to add a method specific to builder of specific type only mike <mikaelpetterson@hotmail.com> - 2021-11-26 06:15 -0800 Re: how to add a method specific to builder of specific type only Eric Sosman <esosman@comcast-dot-net.invalid> - 2021-11-26 13:09 -0500 Re: how to add a method specific to builder of specific type only Arne Vajhøj <arne@vajhoej.dk> - 2021-11-26 19:13 -0500
csiph-web