I'm having some trouble navigating Java's rule for inferring generic type parameters. Consider the following class, which has an optional list parameter:
import java.util.Collections;
import java.util.List;
public class Person {
private String ...
|
I want to define an interface MyList which is a list of interface MyThing. Part of the semantics of MyList is that its operations don't have any meaning on objects which ... |
I have a little problem understanding the Java language
public class PhonebookEntryList extends List<PhonebookEntry>
{
public PhonebookEntryList(String filename) throws IOException
{
//loadListFromFilename(filename);
...
|
Why are java generics so tricky? I thought I finally understood, but eclipse gives me an error at the line in somOtherMethod below using either of the getOuterList methods below. ... |
Is there a library that would let me write regexp-like queries for lists of objects, just like java.util.regexp matches against strings, which are conceptually like lists of characters?
I want to be ... |
I am quite new to Java ...
I wrote a class called DLPFile
which is basically a container of other objects like Strings, ints, floats, etc.
When putting my files into a ... |
Suppose I have a class that implements an interface:
public class A implements IB
and I have a List<A> that I would like to reference to: List<? implements IB> list.
So that I can ... |
|
What does List<?> mean, does it mean simply a list of objects of unspecified type?
Googling for the string <?> returns nothing useful (:
|
I have several objects that look like this:
class PhoneNumber
{
String getNumber();
String getExtension();
DateTime getLastCalled();
}
class Address
{
String getCity();
...
|
I'm wondering how to iterate over a List with mixed contents using foreach. See the example code below.
public class GenericsForeach {
class A {
...
|
I have a data type that contains a set and a method that expects List<? extends MyClass>. The data type has Set<? extends MyClass>. I need to be able ... |
The List interface is the following:
public interface List<E>{
public boolean add(Object e);
public boolean remove(Object e);
public boolean contains(Object e);
...etc
Why aren't the add, remove and contains methods written like the following?
public boolean add(E e)
public ...
|
To create a List, why doesn't Java allow them to be created then elements added one by one?
This works:
public static List<TrackedItem> create(List<Item> items)
{
TrackedItem[] arr = new TrackedItem[items.size()];
...
|
I am trying to serialize and de-serialize (with Json and ObjectMapper) an polymorphic list of Objects that have the following annotation on the base class:
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
When I write ... |
I have a method whose argument should be "a List of anything". The method will not modify the contents of the List. Is it more correct to define this method as
void ...
|
I have a List of objects that extend another class:
List<? extends Fruit> arguments;
Now, I want to invoke a method on these objects. The invoking class has a method wash for each ... |
Another one of those how do I do toArray() with no warnings questions, but it's different from most of the ones posted here.
How do I rewrite the method implementation (without changing ... |
I have a List that contains a certain superclass (like Vehicle), and I would like to write a method that returns the objects in that list that are instances of a ... |
I have a class, MyObject<T> and a list: List<MyObject<?>>.
Contents of the list (example):
MyObject<Date>();
MyObject<Integer>();
Then the MyObject<T> class contains a function:
public T getValue() {
return this.someAttribute;
}
How can I iterate over ... |
In Apache Commons BeanUtil, how to get a type inside a list ? for example
class Track {
List<Actor> actorList = new ArrayList<Actor>();
}
System.err.println(PropertyUtils.getPropertyType(trackBean, "actorList"));
// it should give me Actor instead ...
|
I am writing a doclet extending com.sun.javadoc.Doclet.
When i want want to document an ArrayList as a field of a method i want to get the type of the generic (e.g. when ... |
I am a bit of confused about java generics
Here is the code
class Base{}
class Derived extends Base{}
WE can instantiate a list like this
List<? extends Base> list = new ArrayList<Base>();
Why cannot I add ... |
I have a class Category that implements the interface CategoryManager. Next there is Card that maintains a List<Category>.
Now I would like to return this list, but with categories as CategoryManager, hence ... |
I want to instantiate an object based on the type of the list(that is Truck) and add to the list, I try something below, but it warns me with "sun.reflect.generics.reflectiveObjects.TypeVariableImpl incompatible ... |
What are the differences between List, List<?>, List<T>, List<E>, and List<Object>?
Now I do not blindly ask this question, so please don't close this thread. Let me first introduce the base ... |
I have to use java 1.4 and am using arraylist structures. I now need to do some re-factoring and it would help if I can use generics. I currently have code ... |
I was just looking at the method defined in the List interface:
Returns an array containing all of the elements in this list in the correct order; the runtime type ... |
Why do we lose type safety when using List and not while using List<Object>? Aren't they basically the same thing?
EDIT: I found that the following gives a compilation error
public class TestClass
{
...
|
I'm using reflection to walk the field members of a class and I need to know for List<> subclasses, what the generic type parameters are.
Given a field that has a type ... |
I have some classes that all implement the same Java interface, which essentially allows fetching SQLite ContentValues associated with the particular implementor, and these classes are grouped into lists in various ... |
I am using RAD6. I wrote the following code.
private List<C1> list;
public List<C1> getList() {
return list;
}
But on second line of above code compiler is giving following two errors.
1: Syntax error on token ... |
What is the difference between List and List<Object> in java?
|
Hi All, I have a generic java List something like this List. The Car object looks like this --------------- public class Car { private String name; private String model; private int year; } --------------- The List collection could be huge in size. I need to create a sublist from this huge list based on a condition. What i am currently doing ... |
You will have to walk through the list until you find the object you are looking for. For example: Custom find(List list, String name) { Custom result = null; for (Custom c : list) { if (c.getName().equals(name)) { result = c; break; } } return result; } (assuming your class Custom has a getName() method). But you should consider using a ... |
Hi All, Currently i have a scenario where in i get a generic list collection as an input parameter. In the method I scrutinize the collection in a for loop and based on some condition I want to nullify the custom object which is part of this collection. I am setting this object to null but still when in another method ... |
Hi, I am experimenting with generics and running into a problem where I cannot set a List extends Object1> I have the following: public interface Order { public List extends OrderItem> getItems(); public void setItems(List extends OrderItem> items); } public interface OrderItem { } public calss OrderItemImp implements OrderItem { } public class OrderImp implements Order { public List getItems() { ... |
Forgive me if this has been asked in another form (I did search and didn't find much), but I'd like to instantiate a List, with generic type information reflectively. For example, here's some code that I'd like to make work (pseudo-java): String someClassname = "java.util.Vector"; Class extends List>> classInstance = Class.forName(someClassname); List> instantiatedList = classInstance.newInstance(); I've been looking around for a ... |
|
With the generic List you are telling the compiler that the List will contain only Customer objects. This modifies the signatures of those methods in List that set, add or retrieve items from the list so that they take or return Customer instead of Object. The code doesn't change in adding an item but the compiler checks that what you're adding ... |
|