generics

Are static members of generic classes shared between types

I'm trying to create a generic class which will have some static functions based on the type. Are there static members for each type? Or only where there is a generic used? The reason I ask is I want a lock object for each type, not one shared between them. So if I had class MyClass<T> where T:class { static object LockObj = new...

no exception when adding false type in list

Hi there, i found a (for my state of knowledge) strange behavior during the adding of a Class type to a list. I have a list which holds all implementing classes of an Abstract class List<Class<MyAbstractClass>> myImplementations. I added a type of a non-derived class and there was no error. Can anyone explain why i can do something lik...

Using expression evaluator to execute dynamic LINQ strings on multiple Enumerables - DLR / NCalc / Flee?

I have a generic object with properties: Class MyObject { public Dictionary<string, Object> properties = new Dictionary<string, Object>(); public object this[string name] { get { return properties[name]: null; } } List<MyObject> People= new List<MyObject>(); People.Add(new MyObject(age = 50, home = "Dublin", name = "Bob", Income...

Java generic cast by parameter type

Hi, what, if at all possible, would be a good solution to implement the following desired functionality where I want to: Cast the return type of a routine to the type of the routine parameter, e.g., // Foo and Bar are two types of Common interface Common{} interface Foo extends Common {} interface Bar extends Common {} // Examp...

.net generic constraints and object inheritance compiling issue

I have the following situation below. This code will throw a compiler error for Test2 The type 'InheritedChild' cannot be used as type parameter 'T' in the generic type or method 'panelGenericIOGrid'. There is no implicit reference conversion from 'InheritedChild' to 'SerializerBase'. public class SerializerBase<T> { } public class...

Taming the type checker in Java Generics

I thought I understood Generics pretty well, but apparently I didn't. Here is the test case of the problem: import java.util.ArrayList; class Job<J extends Job<J,R>, R extends Run<J,R>> {} class Run<J extends Job<J,R>, R extends Run<J,R>> {} class Job2 extends Job<Job2,Run2> {} class Run2 extends Run<Job2,Run2> {} class RunList<J ex...

Are static members of a generic class different for different types in Java?

@Spence asked this Previous Question. So, how's that work in Java? Generic types are discarded at runtime in Java, so what happens to static variables of classes instantiated with different generic types? ...

What do nested generics in C# mean ?

Hi, A bit of a basic question, but one that seems to stump me, nonetheless. Given a "nested generic": IEnumerable<KeyValuePair<TKey, TValue>> Is this stating that IEnumerable can have generic types that are themselves KeyValuePair 's ? Thanks, Scott ...

Convertion of Scala typed collection to Java with an unbounded wildcard, etc. Collection<?>

Problem: Need to implement interface from 3rd party Java library in Scala ... Collection<?> getItemPropertyIds() ... My solution is to use ...<here goes Iterable>.asInstanceOf[java.util.Collection[_]] val props:Map[Object,Property] = ... override def getItemPropertyIds()=props.keys.asInstanceOf[java.util.Collection[_]] Is t...

Pass Expression as a parameter into a Generic method, and plug the Expression into a CreateCriteria?

I have a generic method that exists in EntityRepository that gets entities by Name, which is defined as follows: public IEnumerable<T> GetEntitiesByName<T>(string searchExpression) where T : class, ISearchableEntity, new() { return _session.CreateCriteria<T>() .Add(LambdaSubquery.Property<Fun...

Java generic captures and comparable

This is an implementation of a container that can be compared to any other container with a compatible key. I have a weird error using generics in Java, any ideas? private static class Container <Key extends Comparable<? super Key>, Value> implements Comparable<Container<? super Key, ?>> { public Key key; ...

Java Generics Reflection: Generic field type of subclass

Given two classes like this: class Example1<A,B> { public Map<A,B> someMap = new HashMap<A,B>(); } class Example2 extends Example1<URL, URL> { } Is there any way using reflection that I can determine the component types of the Map for Example2? I know I can do: ParameterizedType t = (ParameterizedType) Example2.class.getFie...

Java generics code compiles with javac, fails with Eclipse Helios

I have the following test class that uses generics to overload a method. It works when compiled with javac and fails to compile in Eclipse Helios. My java version is 1.6.0_21. All the articles I read indicate that Eclipse is right and this code should not work. However when compiled with javac and run, the right method is selected. Ho...

Create List<T> using GetType()

Is it possible to create a List or IEnumerable using GetType(). // If T is Type of Contact I want to Return List<Contact> Test(typeof(Contact));//return List<Type> public static IEnumerable<T> Test<T>(T t) { return new List<T>(); //return List<Type> } ...

How make an array of org.apache.http.Header?

I'm new in Java. I'm trying to do import org.apache.http.Header; Header<NameValuePair> nvps = new HeaderList<NameValuePair>(); //....adding some headers httppost.setHeaders(nvps); but said The type Header is not generic; it cannot be parameterized with arguments <NameValuePair> how I can do it? ...

Finding the difference between the list

Hi i have a List<my_Custom_Class> and List<string>. My custom class has various items in which one is DCN number and list<string> contains only DCN number. So I need to check the List<Custom_Class> contains any dcn from List<string>. For example suppose List1 = List<Custom_Class> and List2 = List<String>. If List1 has 2000 items and ...

Select new object as a parameter while preserving it's run-time-generated type

Consider the following: // select a subset of the DataTable var subset = DataTable.Where(...).Select(row => new { Id = Convert.ToInt32(row["Id"]), Name = row["Name"].ToString(), Email = row["Email"].ToString() }); // or create a new object var subset = new { Id = 1, Name = "something random", Email = "name@domai...

How to treat a dictionary of subclasses as a dictionary of the base class

In C# I have a bunch of objects all inheriting from the same base class. I also have a number of Dictionaries, one for each subclass. What I want to do is add all of those Dictionaries to one List so I can loop through them all and do some work (like comparing the lists etc). In summary Dictionary<string, Child> childObjects = new Di...

What does delphi compiler error E2134 mean?

In some code I am fixing up, which makes heavy use of generics and interfaced types, I am getting error E2134, Type '<void>' has no type info. I believe it is because I am in the middle of a refactor where some deeply nested set of units that all use generics are out of sync, but the error is not happening in a place where I can mak...

How can i use generic class to write useful codes via linq?

i want to use generic class to shorter my codes because 1) GetMaintData(int taskID) RelTypeId and RefMaintenance 2) GetAliSpReqs(int taskID) RelTypeId and RefAliSpReq if you look below method you can see only TypeId and Ref data. i think that i can write new clear codes via generic class like that: http://www.thereforesystems.com/dyn...