>>class parametrizedAction< S >{ void of( S s ); }
>>class parametrizedAction< S, T >{ void of( S s, T t ); }
>What are some ways you'd use this?
As suggested, I have an interface
public interface ParametrizedAction
< Domain >
{ void of( Domain value ); }
Now, I needed to apply it as follows
class AgentStreamAction
implements ParametrizedAction<HttpURLConnection,InputStream>
{ public void of( final HttpURLConnection agent, final InputStream stream )
{ ... }}
Here, »of« is an action with two parameters.
But no way. I had to invent yet another interface name:
public interface BiparametrizedAction
< Domain, Domain1 >
{ void of( Domain value, Domain1 value1 ); }
And then I had to use:
class AgentStreamAction
implements BiparametrizedAction<HttpURLConnection,InputStream>
{ public void of( final HttpURLConnection agent, final InputStream stream )
{ ... }}
Piotr Kobzda - 11 Jul 2007 13:54 GMT
> Now, I needed to apply it as follows
Alternatively, you can define a marker (non generic) Domain interface
and various (generic or not) interfaces extending it, for example:
public interface Domain {}
public interface D1<P1> extends Domain {
P1 getP1();
void setP1(P1 value);
}
public interface D2<P1,P2> extends D1<P1> {
P2 getP2();
void setP2(P2 value);
}
public interface D3<P1,P2,P3> extends D2<P1,P2> {
P3 getP3();
void setP3(P3 value);
}
/* and so on...*/
And then have a single action interface defined that way:
public interface ParametrizedAction<D extends Domain> {
void of(D domain);
}
The actions then might be implemented as follows:
public class AgentStreamAction
implements ParametrizedAction<D2<HttpURLConnection,InputStream>>
{
public void of(D2<HttpURLConnection,InputStream> domain) {
of(domain.getP1(), domain.getP2());
}
public void of(HttpURLConnection connection, InputStream stream) {
/*...*/
}
}
That above "domains" model might be nicely supported with reflection,
for e.g. generic abstract Action class implementing "of(Domain)" method,
or some utility classes like Proxy-based universal domains implementation.
piotr
Ingo R. Homann - 11 Jul 2007 14:13 GMT
Hi Stefan,
Im am not sure if I understand you correctly. Do you want a variable
parameter list like in "void foo(String... strings);" but with different
types? If yes, then again the question "Why?", but if you only want it
for one and for two parameters, then the question: "What's wrong with
defining two different interfaces for that? Why invent a new language
concept for that?"
Ciao,
Ingo