1
vote
1answer
54 views
List<E> doesn't like my custom class
I am trying to declare a list<Tuple<String,String,String> where Tuple<String, String, String> is a class that I rolled myself.
public static void main(String args[]) {
...
1
vote
1answer
16 views
Generics Bounded Type Parameter
I have this design, and I'm not sure why it doesn't work.
interface BaseType {}
interface TypeA extends BaseType {}
interface TypeB extends BaseType {}
interface Query<T extends BaseType> {
...
4
votes
2answers
59 views
Issue with declaration of Map<String,Class<? extends Serializable>>
Java provides me by <? extends class> a way of filtering the java classes that you can use to
build in this case the new HashMap, for example:
I can do that:
Map<String,? extends ...
1
vote
2answers
88 views
Generic method without parameters
I was confused with my code that includes a generic method that takes no parameters, so what will be the return generic type of such a method, eg:
static <T> example<T> getObj() {
...
12
votes
5answers
298 views
Why does this class compile even though it does not properly implement its interface?
a List then Why does the code (below) compile? Surely MyClass2 should return a List<Integer> ?
public class Main {
public static void main(final String[] args) {
MyClass myClass = new ...
-2
votes
2answers
42 views
actual difference between creating object using superclass reference
What is benefit to create a object using super class reference?
like
class People{
}
class Child extends People{
}
public class Demo{
public static void main(String []){
People p=new Child(); ...
1
vote
3answers
30 views
Implement interface other than from class signature
Let's say, for example, that I wanted to group some classes in a jar library all fit the definition of my custom interface. Since I can't edit the classes inside the jar in order to implement my ...
-1
votes
1answer
29 views
Utilizing a Generic class inside a method that receives a generic as parameter
don't know how to do this, but is there any way to do something like this
public class Service<T>{
public T save(T object){
//GenericDao is a generic class
...
6
votes
2answers
112 views
Why isn't a conversion to “GenericType<?>” allowed here?
This code causes a compile error with javac (but, notably, not with Eclipse 4.2.2!):
public interface Foo<T> {
}
class Bar<T> implements Foo<Iterable<T>> {
}
class Test {
...
-2
votes
4answers
65 views
Java generics wildcard entry
In JAVA generics, why is this not valid:
List<?> l = new ArrayList()<?>;
Considering that this is valid:
public interface someList<?>{}
There are both unbounded wildcards. In ...
1
vote
1answer
39 views
Java Generic List Template
I created a ListPrinter (main class) and a ListHolder class.
I was taught how to create a generic ArrayHolder but now I am trying to modify it (my homework) to a LIST Holder.
my teacher's Array ...
0
votes
1answer
66 views
Java, Subclass return generics of generics
Does anyone can tell me how to code the return in the function "getDirectHair()" ?
I want to create a method which is like a shortcut in the Human class to directly return the good type of Hair class ...
1
vote
1answer
40 views
CDI : inject two generics from the same template
My problem is that I cannot inject multiple templates instances from GenericManagerJPA<>.
That's to say that in this code, both projectManager and userManager will contains the same ...
4
votes
4answers
79 views
Why does Java allow the explicit conversion of expressions of type Object to A<B<C>>, of type A<?> to A<B<C>> but not of type A<B<?>> to A<B<C>>?
Java will let me do this:
public static class SomeType<I>{}
private static Map<Class<?>, Object> m = new HashMap<Class<?>, Object>();
public static <X> ...
1
vote
1answer
51 views
“Unchecked generic array creation for varargs parameter of type Matcher <? extends String> []” warning using CoreMatchers.allOf()
In my UT code, extract below, I see warning :
Unchecked generic array creation for varargs parameter of
type Matcher <? extends String> []
I have read in another stackoverflow answer ...