generics

Are Java Generics totally and utterly pointless?

I am new to Generics. I have worked through the following Sun trail, but think Generics are completely pointless: http://download.oracle.com/javase/tutorial/java/generics/generics.html Am I missing something fundamental? Because it seems to be that, if the argument was an Integer rather than an Object, you'd get the same behaviour as ...

Java Generics Conundrum

Hi, Here's the relevant code: public interface Artifact {} public interface Bundle implements Artifact {} public interface Component implements Artifact {} public interface State<T extends Artifact> { void transition(T artifact, State<T> nextState); } This allows me to define this enum: enum BundleState implements State<Bun...

public List<(Of <(<'T>)>)>..::..Enumerator?

I'm looking at the MSDN docs about List.GetEnumerator. They say the C# method signature is: public List<(Of <(<'T>)>)>..::..Enumerator GetEnumerator() I was expecting this much simpler signature: public List<T>.Enumerator GetEnumerator() What does their signature mean, with all the punctuation and the "Of" keyword? Edit: Well, I ...

C# Repository using Generics

I have the following repository that I use for unit testing: public class MyTestRepository<T> { private List<T> entities = new List<T>(); public IQueryable<T> Entities { get { return entities.AsQueryable(); } } public T New() { //return what here??? } public void Create(T entity) { ...

Generic defined in unit breaking debug information

This must be a Delphi bug... I have a unit which is the basis of my persistance framework. In that unit I have a base class for all my domain objects, a list class and a generic list class. Just recently I noticed that when I step into the unit when debugging, execution will jump to a point a little further down in the file than it sho...

Scala : parameterize a type with one of its inner types

I would like to parameterize a type with one of its subclasses. Consider the following: class DataLoader { class Data { /* data specifics to this data loader */ } def getData : Data /* and so on */ } Now I want to make this loader able to asynchronously retrieve data from the network. One of the options is to have it subclass Call...

the add method of LinkedList (with supertype) isn't every thing alright ?

package pkg_2; import java.util.*; class shape{} class Rect extends shape{} class circle extends shape{} class ShadeRect extends Rect{} public class OnTheRun { public static void main(String[] args) throws Throwable { ShadeRect sr = new ShadeRect(); List<? extends shape> list = new LinkedList<ShadeRect>(); ...

What's differences between every declaration and what's the implications on every one?

List listOne = new LinkedList<Shxx>(); List<Shxx> listTwo = new LinkedList<Shxx>(); List listThree = new LinkedList(); List<Shxx> listFour = new LinkedList(); ...

Java generics and the Number class

I want to create a method that compares a number but can have an input that is any of the subclasses of Number. I have looked at doing this in the following manner... public static <T extends Number> void evaluate(T inputNumber) { if (inputNumber >= x) { ... } } I need to get the actual primative before I can perform the comp...

Generic Edit in repository

public T Update(T update) { } Currently for this method I m implementing it like so..is there any other easy way around in Linq to SQL public T Update (T update) { var table = (IEnumerable<T>)(_table.AsQueryable()); var store = (T)((from a in table.Where( a => a.GetType().GetPrimaryKey() == update.GetType(...

Compliment List of a sub List

listSuper listSub_A listSub_B Is there any extension methods that replace the following piece of code? foreach(int a in listSuper) { if (!listSub_A.Contains(a)) { listSub_B.Add(a); } } In short I want to fill listSub_B with elements in listSuper which are not in listSub_A. ...

Can generics avoid me passing back a, uh, generic 'Object'?

I've got the following JAXB unmarshalling code which I'm trying to generalize. Here's what it looks like: private Object getResponseObject(String stubbedXmlFile, Class jaxbInterfaceClass, AbstractRepository repository) { Object responseObject = null; try { JAXBContext jc = JAXBContext.newInstance(jaxbIn...

Use interface to convert collection of objects with extensions and lambdas

I have some objects like user, address and so on, and Im converting them to business objects using extension methods: public static UserModel ToPresentationForm(this User pUser) { return new UserModel { ... map data ... }; } Also I need to convert strongly typed collections...

C# extension method to check if an enumeration has a flag set

I want to make an extension method to check if an enumeration has a flag. DaysOfWeek workDays = DaysOfWeek.Monday | DaysOfWeek.Tuesday | DaysOfWeek.Wednesday; // instead of this: if ((workDays & DaysOfWeek.Monday) == DaysOfWeek.Monday) ... // I want this: if (workDays.ContainsFlag(DaysOfWeek.Monday)) ... How can I accomplish th...

How to create generic method

Hi All, I want to create a method which will take some base type as a parameter and compares and check if it is derived type and return the derived type based on that. For Example: Class A : IBase Class B : IBase My method: Public IBase GetData(IBase type) { If type is A then { //do smthing return A } If type is B { ...

What code allows me to have this syntax ClassName<datatype>()

Hi, I noticed that the Ninject API has calls such as Bind<ISomething>().DoSomethingElse(); How is this achieved? ...

How can I rewrite these two almost identical functions using c# generics?

Hello chaps I have two almost identical c# functions. Because they're so similar I thought I'd try out generics, but I'm stumped on how to do it. Any suggestions, or am I barking up the wrong tree entirely? public IList<UnitTemplate> UnitTemplates { get; set; } public IList<QualTemplate> QualTemplates { get; set; } public ...

Java Generics and interfaces

Having this design : interface Foo<T> { void doSomething(T t); } class FooImpl implements Foo<Integer> { //code... } interface Bar extends Foo { //code... } class BarImpl extends FooImpl implements Bar { //code... } It gives me Compile Error : The interface Foo cannot be implemented more than once with differ...

Templated Functions.. ERROR: template-id does not match any template declaration

I have written a function template and an explicitly specialized templated function which simply takes in 3 arguments and calculates the biggest among them and prints it. The specialized function is causing an error,whereas the template works fine. But I want to work with char* type. This is the error I get=> error: template-id ‘Max<>...

How do I reconstruct generic type information for classes given a TypeLiteral?

I have the following problem: Given a Guice type literal TypeLiteral<T> template and a class Class c implementing or extending T, construct a type Type t which is equivalent to c with all type variables instantiated so as to be compatible with template. If c has no type variables, it's easy; c is the type in question. However, if ...