I have the following:
public class Foo<T extends Grok> extends ArrayList<T> {
}
How can I find the class name represented by T at runtime? For instance, let's say I allocate like this:
Foo<Apple> foo ...
|
I know that in order to create an object of ArrayList type I need to:
ArrayList<MyType> l = new ArrayList<MyType>();
I know it because I've seen this in books.
But looking at Java SE ... |
Is it possible to make a child class that extends ArrayList? If so, how?
|
First this IS a Java question so forgive this first C#-related explanation...
I've most recently been using C# where one .cs source file can contain multiple class definitions, example...
// Servers.cs
public class Server ...
|
I'm having a bit of a problem grasping something - I might be going about this completely wrong.
I am trying to create a class which extends ArrayList but has several methods ... |
I have two classes named "BaseCatalog" and "City". "BaseCatalog" is the parent class of "City", in other words, "City" extends "BaseCatalog" class.
I have a method called "getBaseCatalogObjects" which takes one ... |
I'm having some trouble in the following code.
public ArrayList<? extends IEvent> getEventsByDateRange(DateTime minStartTime, DateTime minEndTime)
{
ArrayList<? extends IEvent> returnedEvents = new ArrayList<GoogleEvent>();
returnedEvents.add(new ...
|
|
I'd like to extend ArrayList to add a few methods for a specific class whose instances would be held by the extended ArrayList. A simplified illustrative code sample is below.
This ... |
I have a class GDBTrack, that has some class variables and an ArrayList of GDBTrackPoints. The GDBTrackPoints can be manipulated in all the ways that the contents of an ArrayList would be: add, addAll, remove, clear etc. Currently I have a getter that returns the ArrayList and lets the calling class use the ArrayList methods to access the GDBTrackPoints. I'm wondering ... |
|
Yes thanks, that seems to solve the issues. I find it interesting that only appears in the class "declaration" and is not referenced anywhere else. It's my first exposure to this kind of thing, so I guess I have some research to do to find out how this works. One more thing for the todo list. I'm assuming that If ... |
|
It's a bit of a quandary when to extend or "wrap" something like a List. I used to always wrap them (i.e. I used an instance field to store the list, and coded my own get or add methods to add to that hidden list). An example might be a "Classroom" that that would have methods for adding or removing students. ... |
Hello. I am writing a card game program, but I cannot figure out how to write a swap() method with which to shuffle the cards. I have created a class DeckList that extends ArrayList (I did this to to override the toString method so that it displays the Cards instead of the memory addresses of these cards). I am trying to ... |
hi, I was wondering if some one could spare time enough to explain why an ArrayList will have to extend an AbstractList and implement List, RandomAccess, Cloneable, Serializable. Wouldnt it be enough that it just implemented List (Thats what I thought so far) ? I know. it implements these interfaces for the functionaluty being cloneable.. serializable and actually being a list. ... |
|
Thanks for all the responses guys, I have tried using your code dcminter and it gives me the same error I was getting before I tried using the '.intValue' method. That is that the '+' operator cannot be applied to Integer. I have researched this before and am sure this is because an object Integer is returned and not an int. ... |
japanir wrote: readFile(String filename) Your question has already been answered very nicely, but there's one tiny hint that I'd like to give here. Whenever I write a method that looks like this: "load(String filename)" I'll find that I regret it sooner or later. Because at first I only want to read from a file, then I'll realize I might want to ... |
Why extend ArrayList? Is it because the functionality you're creating is really for a special kind of ArrayList, and doesn't make sense in a LinkedList? Does it only make sense for Lists, not for other Collections, like Sets? If it really is functionality that only makes sense as a special kind of ArrayList, then yes, extending ArrayList is the right approach. ... |
In my program, there are two classes (well, two that I'm concerned about), the first is called Unit and the second is called Peasant. -Unit has all the basic functions that all units will need, such as movement, attack, etc. -Peasants, being a unit, extends the class Unit. However, they must be able to gather resources as well, so I've added ... |
|
|
Okay, this might not be so bad after all then. But there are a couple of things I don't understand. Why is it necessary to make a createObject function? I understand that it's because it needs to return an E type, but since E extends Object1, shouldn't Object1 also suffice, and therefore Object1 o = new Object1(i); aList.add(o); should work too? ... |