generics

Java generic class and wildcards

Hi all, I've got a problem with generic classes in java. I've got this class: public abstract class MyMotherClass<C extends AbstractItem> { private C item; public void setItem(C item) { this.item = item; } public C getItem() { return item; } } An implementation of this class can be: public...

convert a list of objects from one type to another using lambda expression

I have a foreach loop reading a list of objects of one type and producing a list of objects of a different type. I was told that a lambda expression can achieve the same result. var origList = List<OrigType>(); // assume populated var targetList = List<TargetType>(); foreach(OrigType a in origList) { targetList.Add(new TargetType(...

what is the difference between 'super' and 'extends' in Java Generics

I am trying to learn Java generics. I am not clear when you will use <T extends Foo> and when you will use <T super Foo>. What do each one of these things mean about T? Lets say I have <T extends Comparable> and <T super Comparable>, what do each of these mean? I've read several tutorials at sun.com but I'm still lost. Can somebody illu...

Exception on creating a EDMX/DB-Schema using Entity Framework 4 using ContextBuilder with a generic class.

I'm using the Microsoft.Data.Entity.CTP (in the Entity Framework CTP) under the .NET 4 framework to create the EDMX metadata from my C# classes to create a database schema. I setup a simple model as such: public class AModelContainer : ObjectContext { public IObjectSet<RegularClass> RegularClasses { get { return CreateObje...

How to group generic classes?

I am working on a generic game engine for simple board games and such. I am defining interfaces that I will require each game to implement I have classes like IGame, IGameState, IBoardEvaluator, and IMove. I have methods like IGame.PerformMove(IMove move), that I would like to restrict. If I am playing tic-tac-toe I would like to enforc...

Instantiating a class assignable to Collection

I want to check if a given Class is assignable to a java.util.Collection, and if so create a new instance of it. I tried the following: Class<?> clazz = ... // I got this from somewhere if (!clazz.isInterface() && java.util.Collection.class.isAssignableFrom(clazz)) { java.util.Collection<?> collection = clazz.newInstance(); } ...

generic stored procedures in oracle

i want to write a generic stored procedure in oracle .For example i want to take table name as input and then do maipulations on it. I want to learn some sample generic codes and the basica of writing generic stored procedures in oracle. Can any one provie code snippets/ links to websites or other material for this? ...

Create intance of any C# class by generic way

i want to create instance of any class by generic way. is that possible?i know ,this is madly but this is only a question waits the its answer. i tried this but doesnt work. public class blabla { public void bla(); } public class Foo<T> { Dictionary<string, Func<object>> factory; public Foo() { fac...

Does .Net typecast when an object is used in collection using generics?

Does .net CLR typecast the objects to the ones mentioned in the collection declaration? If i declare a List<string> lststrs= new List<string>(); lststrs.add("ssdfsf"); does .net typecasts this object while adding and retriving????? Well i think the question itself was not clearly understood by everyone.Let me elaborate. In java ther...

java generic wildcards

Currently I'm working on a service interface which retrieves domain objects based on a primary key. However I get the feeling I'm not efficiently using generics. Base domain objects look as follows: public interface DomainObject<PK extends Serializable> extends Serializable { PK getID(); } My service interface looks as follows: ...

How to cast List<Object> to List<MyClass>

Hello these, This does not compile, any suggestion appreciated. ... List<Object> list = getList(); return (List<Customer>) list; Compiler says: cannot cast List<Object> to List<Customer> ...

generic stored procedure in oracle

I want to write a PLSQL stored procedure that accepts a table name as argument. This table is source table. Now inside my procedure i want to manipulate the fields of that table. EX: I want to insert the records of this source table into another target table whose name is XYZ_<source table name>. The column names for source and targ...

List<? super B> lsb = new ArrayList<A>(); Logical error in java?

We have: class A{} class B extends A{} class C extends B{} class D extends C{} we can define Lists like: List<? super B> lsb1 = new ArrayList<Object>(); //List<? super B> lsb2 = new ArrayList<Integer>();//Integer, we expect this List<? super B> lsb3 = new ArrayList<A>(); List<? super B> lsb4 = new ArrayList<B>(); //List<? super B...

C# typed <T> usercontrol in design mode gives error

I've got a custom class, which derives from UserControl. The code: public partial class Gallery<T> : UserControl where T : class, IElement, new() This classworks like it's supposed to work. But, when I try to enter design mode of the form which contains these Gallery classes, it gives me errors: Could not find type 'PresentrBu...

How do I iterate a generic reflected method?

In my CMS I have a load of modules which allow me to do some clever item listing stuff. I am trying to use them to pull out a list of their child objects via reflection, but am getting stuck with the level of generics involved. I have got as far as this method: var myList = moduleObj.GetType().GetMethod("ChildItems").Invoke(moduleObj, ...

Problem using generic map with wildcard

i have a method that returns a map defined as: public Map<String, ?> getData(); the actual implementation of this method is not clear to me, but: when i try to do: obj.getData().put("key","value") I get following compile time error message: The method put(String, capture#9-of ?) in the type Map is not applicable for the ar...

Creating an IList<T> of Item<U>?

So I have an object, lets say Item<U>. I want to create a(n) (I)List<T> containing a collection of these items. The problem that I am running into is that the collection of Item<U> can have any number of different types for U in them. What I can not figure out is the signature to use for the IList. I tryed IList<Item<T>>, but because...

Generic collection of generic classes?

I have a class that I fill from the database: public class Option<T> { public T Value { get; set; } public T DefaultValue { get; set; } public List<T> AvailableValues { get; set; } } I want to have a collection of them: List<Option<T>> list = new List<Option<T>>(); Option<bool> TestBool = new Option<bool>(); TestBool.Value = tr...

WPF windows organization techniques

Hello, Im developing some wpf app. Basically i have two types of windows: search windows and insert/edit windows. When i developed win forms apps, i used a trick, called MdiParent. In that way i had ability to put my caled search type windows in a "stack". In orher words if i called 5 different search windows from meniu, they apeared in ...

Why isn't Collections.binarySearch() working with this comparable?

I have this Player class which implements the Comparable interface. Then I have an ArrayList of Players. I'm trying to use binarySearch() on the list of Players to find one Player, but Java is giving me a "cannot find symbol: method binarySearch(java.util.ArrayList< Player>,Player)". This the Player class: class Player implements Compa...