Re: abstract classes and generic types
On May 17, 3:29 pm, Mark Space <marksp...@sbc.global.net> wrote:
I think I came up with the same thing Giovanni did, except "put" needs
to return a String to match your example.
horo...@gmail.com wrote:
abstract class a<U>> {
String calculate() { return this.put(this.my_func()); }
abstract String put( U u );
abstract U my_func();
}
Otherwise use this the same way as his example.
Note: you can' parameterize with primitives. If you want to use flo=
at
or int, gotta write those by hand yourself. Sorry.
Ok, I guess I'll morph this issue a bit. I came to the conclusion that
generics were the way to go, but why should I need to define a
parameter with a class to do what I want to do?
I think of the types of variables in an object as implementation
details.. But the following doesn't work:
import java.util.*;
class AA
{
Set<?> example;
aa()
{
example = new HashSet<Integer>();
_setHelper(example, new Integer(1));
System.out.println(example);
}
private<K> void _setHelper(Set<K> parm, K key)
{
parm.add(key);
}
}
where I'm attempting to give the compiler a little push in the right
direction, showing that Set<K> should be linked with the ?. I would
have thought this would have worked, but no.
Of course, if I explicitly cast it - (Set<Integer>)example, it works,
but that gets rid of the point of generics, doesn't it?
So any ideas around this?
(ps - wrt language lawyering, with all respect I detest camelcase, and
will only use it if required by convention. And no - I don't go around
naming my variables mySet, etc.. I do it for example.. so thanks for
the concern, but no thanks..