Generic programming is a style of computer programming in which algorithms are written using type parameters which are later substituted with concrete types.

learn more… | top users | synonyms (2)

-4
votes
0answers
17 views

Cause for American surveillance program [closed]

This is not a programming language but maybe I get some clarification. What might be the cause for the American surveillance program? What can a government really do with personal profiles? What do ...
0
votes
1answer
19 views

Is it possible to have a generic Razor view to work with a generic model?

I'm working on a list generator using MVC.Net. I have created ColumnInfo<T> and Report<T> classes as follows: public class ColumnInfo<T> { public string Title{get;set;} ...
2
votes
2answers
74 views

Storing different types of elements in a List in Java

I'm trying to develop a general table loader which schema is known at runtime. This requires having a class which contains a list of different types of elements and supports various get and set ...
2
votes
3answers
43 views

Implementing Comparable, compareTo name clash: “have the same erasure, yet neither overrides the other”

I'd like to have a compareTo method that takes a Real (a class for working with arbitrarily large and precise real numbers [well, as long as it's less than 2^31 in length at the moment]) and a ...
1
vote
1answer
39 views

Java generics: Generic types of type variables?

How would I express the following type relationship in Java generics: class MyClass<T> { } interface MyInterface<T extends MyClass> { void m1(T<Integer> argument); void ...
3
votes
1answer
65 views

Can self typing be used with abstract types?

I'm trying to achieve F-bounded polymorphism without using generics. I also need to use self-typing as I will be referencing this and expecting it to be typed as the subtype. trait MyTrait[T] { self: ...
0
votes
1answer
22 views

Difficulties with assigning a generic in VHDL

I am relatively new to VHDL and am facing problems with generics. I want to assign a signal value to a generic. Can that be done? architecture rtl of entity_name is signal ibaudratetop: integer; ...
4
votes
4answers
102 views

How do i convert a class (which is derived from a generic “base” class) to that generic “base” class

I created a base class ("Element") and a base list class ("Elements") as generic class. The generic list class should only be able to contain classes, which are of Type "Element" of derived from ...
6
votes
4answers
106 views

casting Object[] to a reference type array in java

In implementation of a generic stack ,the following idiom is used and works without any problem public class GenericStack<Item> { private int N; private Item[] data; public ...
1
vote
3answers
77 views

Java Generics limit type

In Java i have the following Class Structure: class All +-- class A extends All +-- class B extends All class ContainAll +-- class ContainA extends ContainAll +-- class ContainB extends ContainAll ...
0
votes
1answer
28 views

Base class type of the derived classes, Generics - .net

I read about contra and covariance problem and it looks like my code falls into that category. I just want to confirm whether i am doing something else wrong. I am using VS 2005 (company policy..) I ...
0
votes
2answers
36 views

Abstract class inheriting from non-abstract in .NET?

I'd like to know if a subclass of a concrete (that is, not abstract) class can be abstract or not. In a fictitious example: public class HistoricallyManaged<SpecificType> { // code to manage ...
1
vote
1answer
49 views

How to use generic types in method signature?

I have this signature public final <T1 extends Pair<Pair<T3, T4>, Pair<T3, T4>>, T3 extends Enum<MyConstant>, T4 extends BigDecimal> ...
0
votes
2answers
75 views

converter between different Java types

I'm trying to implement a converter between different types in java: I have a super class foo that have 2 sub classes: foo1 and foo2, I also have 2 unrelated other classes bar1 and bar2 and I’m trying ...
1
vote
1answer
55 views

Generics : Specify that parameter must be an interface

I try to do a generic class like this : public abstract class MyClass<A extends MyInterface,B,C> implements A{ ... } (Note: B and C are not interfaces, just other generic params) I get a ...
1
vote
2answers
89 views

Java: Write a generic method that throws any RuntimeException

I am writing a method that basically does one simple thing, log the error message and throw a runtime exception using the same error message. I want it to be able to throw any child exception of ...
0
votes
1answer
50 views

Params parameter when using optional paramters

I'm am currently writing overrides to provide own implementations of MVC controls. I would like to work with optional parameters so it saves me the work of writing and maintaining multiple overrides ...
1
vote
1answer
47 views

How to create a generic type instance for the following situation

i have the following code, please let me know how to create the instance at runtime without specifying the type while coding. MyObject productobject = something. i need the object of type ...
1
vote
1answer
32 views

How to retrieve an object of a specific subclass?

I have a class 'Entity', that has a list of 'Component' objects. Now, 'Component' is just a root class for a bunch of different subclasses, and each subclass can be represented only once per entity. ...
-2
votes
1answer
45 views

How to get a GenericList sorted by a property

I need to sort a list based on a property (IsValid = true) with all true items on top and the rest below it.Since I'm using compact framework, I can't use OrderBy. Can anyone post me LINQ query to get ...
5
votes
5answers
103 views

What is the benefit of extending a generic by specifying the new type as actual type of generic

I saw this pattern somewhere: class A extends B<A> { } This structure is a little unusual to extend a generic by specifying the new type as actual type of generic. What is the use? Is there ...
2
votes
3answers
77 views

Generic method and invalid context exception

I'm trying to code a custom authorization service where I register a module to check permissions for an specific enum representing available activities: public interface IAuthorizationService { ...
0
votes
1answer
32 views

Iterating the LinkedHashMap shows compilation error

Below is the code for AttributeValue class- @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) @JsonIgnoreProperties(ignoreUnknown=true) public class AttributeValue<T> { private T ...
2
votes
1answer
31 views

Get generic type class in superclass with GWT

I have a GWT client generic super-class SuperClass<T>. There are sub-classes that explicitly define the generic type, like SubClass extends SuperClass<String> and etc. I need to get ...
4
votes
1answer
75 views

Why does inferring of generic type does not work here?

Suppose I have the following classes: interface MyS<T extends MyT<S, T>, S extends MyS<T, S>> { } interface MyT<S extends MyS<T, S>, T extends MyT<S, T>> { } ...
0
votes
1answer
33 views

Referencing the subtype within a trait in Scala

With the vast support for generics in Scala, what is the best way to achieve the following cyclic parameter bounds, where C in Command[A, C] is a subtype of itself (i.e. UserCommand or SystemCommand)? ...
26
votes
8answers
1k views

Operator '??' cannot be applied to operands of type 'T' and 'T'

I have the following generic method, but VS gives me a compile error on that. (Operator '??' cannot be applied to operands of type 'T' and 'T') public static T Method<T>(T model) where T : ...
6
votes
2answers
103 views

Java: Why am I able to have a reference to a non-null array of concrete parameterized types?

I was surprised, but ... this compiles: public <T extends Database> ColMetaData<T>[] getTableColumnsAsEnums() { Class<? extends ColMetaData> cls = ...
0
votes
0answers
13 views

Interfaces in Generic DAO ? What's the real benefit?

I've coding for quite some time now however there certain aspects of inheritance which I an unable to understand. I know that we have four access levels. Public default protected private and very ...
0
votes
2answers
27 views

The best overloaded method match for 'System.Collections.Generic.List<Urun>.this[int]' has some invalid arguments

public Urun(int id) { this.UrunId = id; List<Urun> dr = ManagementLib.UrunBilgisiAl(id, null, null, null, null, null, null, null, null, null, null, null, null, ...
5
votes
5answers
85 views

Assign a subclass of a Generic class to a super class of this class

I have couple of supplied interfaces public interface Finder<S extends Stack<T>,T extends Item> { public S find(S s, int a); } public interface Stack<T extends Item> { ...
0
votes
3answers
41 views

Why can't I use instances of a generic type but can outside?

Consider the following code class SomeClass { } class GenericsExample<E extends SomeClass> { public void createError() { process(new SomeClass()); //Compiler error! } ...
1
vote
2answers
62 views

Cast to interface with generics with reflection

I have simplified the code but basically this code runs on a loop and the types come from reflection. The only constant here is the IWorker<T> interface. I need to access the properties of the ...
0
votes
2answers
44 views

Unable to cast object of type 'System.Linq.OrderedEnumerable`2[***]' to type 'System.Collections.Generic.IEnumerable`1[***]'

I have an object DirectoryToken that inherits from the class Token. In my code I have a GetValues method which takes a list of tokens, and puts together the value for each item in the list based on ...
1
vote
4answers
34 views

Java Pass instance type of Object to generic class type parameter

Is it possible to pass an Objects instance type as the type parameter of a generic? Something like the following: Object obj = new Double(3.14); //Instance type Double //Could I do the following? ...
-1
votes
2answers
62 views

Generics issue again. How can this method return correctly?

I have a class called Custom and want to be able to have a method getAll(Class) that returns type Collection of Custom when it is passed the Custom class as an argument. Collection<Custom> c = ...
0
votes
2answers
62 views

How can you use generics to make universal methods in Java?

I have two classes, classB and classC, that both extend classLetters. In a separate class, which classB and classC call to, there are two methods: getBType() and getCType(). The code within the two ...
4
votes
2answers
105 views

Filtering collection with generics in java

I have the following type of collection: Collection<GenericMessage<Collection<Client>>>; Collection<GenericMessage<Client>>; ...
-2
votes
3answers
58 views

External Key Value Pair Data To Dictionary C#

I have an external resource that keeps information as key-value pair (say file, typically an xml), I want to load this info into application as a Dictionary<Key,Value> (Generics). I'm seeking ...
1
vote
4answers
55 views

Why do I get this error “Type mismatch: cannot convert from Serializable to T”?

With the the following code: Main.java // ... private static <T extends Serializable> T doStuff() { Response r = ... // ... return r.getDetails();//Error here } // ... ...
0
votes
1answer
51 views

Java generics: Raw types inside of generic definition

I wonder why the following generic definition does not produce a compiler warning: class MyClass<T extends List> { } and how the above definition is different to class MyClass<T extends ...
2
votes
1answer
70 views

The meaning of 'in, out' in generic delegate declaration

public delegate TOutput Converter<in TInput, out TOutput>(TInput input) What is the meaning of in and out in this declaration?
3
votes
1answer
57 views

Determining if type is a subclass of a generic type

class Program { static void Main(string[] args) { Check(new Foo()); Check(new Bar()); } static void Check<T>(T obj) { // "The type T cannot be used as type ...
0
votes
4answers
63 views

Why does the generic parameter <T> change to <S> in some methods [closed]

This is the class I'm working with in a past exam: class CyclicQueue<T> { private T data[] = (T[]) new Object[100]; // max 100 items private int items = 0, start = 0, next = 0; ...
0
votes
1answer
49 views

Java Reflection/Generic Types for dynamic-like type casting

I am wondering if this is possible. I am creating a class that holds a Number and that number can be a Float or an Integer. However, at runtime, that is decided. I want to make a more elegant ...
2
votes
0answers
31 views

JSF: auto conversion when backing a view item with an instance of a subclass of a generic class with resolved type parameter

We have a hierarchy of generic "parameter" types, with non-generic concrete leaf classes, a vertical slice of it given here: public interface Parameter<T> public T getValue(); public void ...
2
votes
1answer
70 views

How to pattern-match a generic type argument?

I'm currently unable to wrap my head around Scala's TypeTag reflection API. There are very little information to find on the web and all trial and error attempts are leading nowhere. def doStuff[T: ...
1
vote
5answers
83 views

Return a list of a subtype as a List of supertype in C#

I want to make "somehow" the following work: public class GenericsTest<T> where T: ISomeInterface { private List<T> someList = new List<T>(); public ...
0
votes
1answer
50 views

Scala Data Modeling and Generics

I'm using the Play Framework and Squeryl to make a fairly basic front end for a database, but I know I'm rewriting too much code. I have different models to represent data in my db, and they all do ...
0
votes
2answers
73 views

Using Java Generics error

I have the following code: String test = "[{\"color\":\"red\"}]"; Class<? extends Base> baseObject = Base.class; Collection<? extends Base> elements = new ArrayList<Base>(); if ...

1 2 3 4 5 258
15 30 50 per page