Possible Duplicate:
Java Generics: Why Does Map.get() Ignore Type?
Could someone please explain why with Map defines
V put(K key,V value);
V get(Object key);
Why is get not defined as:
V get(K key)
Similarly, why are these methods typed to Object, and not K and V respectively?
boolean containsKey(Object key); // Why no...
Hello all,
I need to outline a little bit of background info for context. Please bear with me and I'll try to simplify my question as much as possible:
I have one object that inherits from another object. We'll call the first object Fruit and the second Apple. So I've declared Apple as follows:
public class Apple : Fruit
{
public ...
I know that in ASP.NET (talking about 2.0 here primarily) one can set a property on an object that takes a collection of things (an enumerable type I'm guessing is the trigger) and then reference it declaritivly. For example:
<ObjectDataSource properties="blahblahblah">
<SelectParameters>
<asp:Parameter />
</SelectParam...
I get a warning about unchecked casts on the "return (T) value;" line. Is there a better way to do this, or should I just suppress the warning?
class SomeClass<T>
{
/* ... other methods ... */
private Set<T> aSet;
public T filter(Object value)
{
if (this.aSet.contains(value))
return (T) value;
...
Hello everyone.
I'm having a problem that I have encountered before, but I still don't know why it happens.
This is the code:
package Program;
import java.util.ArrayList;
import java.util.Iterator;
/**
* This class will hold the full collection of the user.
*
* @author Harm De Weirdt
*/
public class ShowManager {
/**
* ...
Hello all
I have two complex dictionaries in the form
Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>>
So as you see i've inner dictionaries. I want to write a generic recursive function which can merge two complex dictionaries of this form (or any other complex form of dictionaries), by calling itself passing...
Dynamic Inheritance
I have a situation where I want a class (which is a JPA entity) to be able to extend either class A or class B dynamically. My thought was to use Generics, but it looks like generics doesn’t support this. For example:
@Entity
public abstract class Resource() {
...
}
@Entity
public abstract class Snapshot() {
...
}...
I have a recursive object, a linked list really:
public class LinkedList
{
public string UniqueKey { get; set; }
public LinkedList LinkedList { get; set; }
}
LinkedList will have some object graph that will eventually end in LinkedList.LinkedList == null.
I would like to take all the objects in the graph and put them into a ...
I am trying to get a generic tree backing-bean to work. I have one generic class called ACLTree, and then an implementation of it.
In my JSF document I try to access a value per #{mybackingbean.property}.
But I get an ELException:
javax.el.ELException: /modules/useradmin/acl.xhtml @30,55 value="#{ACOTree.root}": java.lang.IllegalAccess...
I have several objects in C# that's roughly like this:
A: {
Id: 1,
Parent: {
Id: 2,
Parent: {
Id: 3,
Parent: null
}}}
And,
B: {
Id: 4
Parent: {
Id: 2
Parent:
...
I'm a linq noob.... can someone please some me how to achieve this using linq... I'm trying to compare 2 lists in both directions...
internal void UpdateUserTeams(int iUserID)
{
UserTeamCollection CurrentTeams = GetUserTeams(iUserID);
UserTeamCollection UpdatedTeams = this;
foreach (UserTeam ut in Curre...
Using Java Generics, I tried to implement a generic console input method.
public static <T> T readFromInput(String message, Class<?> c) throws Exception{
System.out.println(message);
Scanner scanner = new Scanner(System.in);
try {
if(c == Integer.class)
return (T) Integer.valueOf(scann...
I'm using a HashMap and the method show below to track change listeners for class types. The IDE is giving a warning
[rawtypes] found raw type: java.lang.Class
missing type parameters for generic class java.lang.Class<T>.
What type for Class needs to be specified to resolve the warning?
private HashMap<Class, Set<ChangeListener>>...
I'm trying to work with two contexts in a generic repository and I should invoke the static method GetObjectContext() with dynamic type like ObjectContextManager<DynamicType>.GetObjectContext().
private DataContext GetDataContext()
{
Type type = GetContainerType();
Type paoloGenericClassType = typeof(ObjectContextMan...
I'm developing in Windows 7 64-bit with Visual Studio 2008. I have a collection of class libraries that I merge into a single DLL using ILMerge. When I try to use this merged DLL, however, I get
[BadImageFormatException: Could not load file or assembly 'MyMergedDll' or one of its dependencies. An attempt was made to load a program ...
Given a simple generic class:
class EqualsQuestion[T]( val value :T )
it seems reasonable that the following code would resolve to "false":
val a = new EqualsQuestion[Int]( 5 )
val b = new EqualsQuestion[Long]( 5 )
a == b
(Yes, it's a contrived example. In my real code I wanted '==' to fail if the type parameters are different, re...
With an abstract class I want to define a method that returns "this" for the subclasses:
public abstract class Foo {
...
public <T extends Foo> T eat(String eatCake) {
...
return this;
}
}
public class CakeEater extends Foo {}
I want to be able to do things like:
CakeEater phil = new CakeEater();
phil.e...
I've got a class Foo<T>. How can I say that I want T to be some class implementing BarInterface? Writing simply class Foo<T implements BarInterface> doesn't compile.
...
How can I combine two lambda expressions into one using an OR ?
I have tried the following but merging them requires me to pass parameters into the Expression.Invoke calls, however I want the value passed into the new lambda to be passed onto each child-lambda..
Expression<Func<int, bool>> func1 = (x) => x > 5;
Expression<Func<int, boo...
I'm currently playing with implementing various sorting algorithms in Java, mostly for fun, but I'm struggling with how to do it 'right'. That is, I want the user to be able to call the sorting algorithm of choice on anything that is comparable - ints, longs, Strings, booleans (actually, are these comparable in Java?), their own classes;...