Meta technique, that allows to pospone the setting of the dependable type to the runtime.

learn more… | top users | synonyms

36
votes
7answers
6k views

What is wrong with Java's generics? [closed]

I have seen several times on this site posts that decry Java's implementation of generics. Now, I can honestly say that I have not had any issues with using them. However, I have not attempted to make ...
32
votes
6answers
2k views

Good or bad practice to mask Java collections with meaningful class names?

Lately I've been in the habit of "masking" Java collections with human-friendly class names. Some simple examples: // Facade class that makes code more readable and understandable. public class ...
24
votes
1answer
4k views

Java: “Heap pollution”

A "Heap Pollution" as in Non-Reifiable Types (The Java™ Tutorials > Learning the Java Language > Generics (Updated)) Why is it called that way?
14
votes
8answers
1k views

How to spread awareness for generic programming among team members?

I am staying in an environment, where people believe: Java generics are the feature exclusively used for library writing and not for the real coding. C++ is an OO programming language; template is ...
12
votes
1answer
864 views

Scala as a language for Generic Programming

In the paper “An Extended Comparative Study of Language Support for Generic Programming” by Garcia et al. an interesting comparison of programming languages features for generic programming is given: ...
10
votes
3answers
1k views

generic programming, how often is it used in industry

I do programming in an academic setting at the moment, so I can use whatever I want. I'm using the boost graph library for a few things, and I'm wondering whether investing effort in understanding GP ...
10
votes
2answers
482 views

How are generics implemented?

This is the question from compiler internals perspective. I am interested in generics, not templates (C++), so I marked the question with C#. Not Java, because AFAIK the generics in both languages ...
9
votes
3answers
1k views

Why should we preferably use first class collections?

As per rule number 4 of Object Calisthenics by Jeff Bay (RTF) in The ThoughtWorks Anthology, it is recommended that one should "Use first-class collections". Rule 4: First class collections ...
9
votes
4answers
6k views

Who extends interfaces? And why?

AFAIK, my class extends parent classes and implements interfaces. But I run across a situation, where I can't use implements SomeInterface. It is the declaration of a generic types. For example: ...
9
votes
2answers
436 views

Why is there a new() constraint in C# but no other similar constraint?

In C# generics, we can declare a constraint for a type parameter T to have a default constructor, by saying where T : new(). However, no other kinds of constraints like this are valid - new(string) ...
8
votes
5answers
2k views

What's a good naming convention for generic types in C#? [closed]

I decided to ask this question here instead of on stack overflow because it is rather subjective. In C#, typically I see generic types with very poor names. Specifically, "T" is commonly used but is ...
8
votes
3answers
7k views

Difference between various Collection Generic Interfaces in C#

I have been playing around with C# for Windows and ASP.net MVC development for some time now. But I am still unclear on a few areas. I am trying to understand the basic difference between and ...
7
votes
1answer
402 views

Why prefer a wildcard to a type discriminator in a Java API (Re: Effective Java)

In the generics section of Bloch's Effective Java (which handily is the "free" chapter available to all: http://java.sun.com/docs/books/effective/generics.pdf), he says: If a type parameter ...
6
votes
1answer
425 views

Why can't java generics be in arrays?

Why is it that when I try to make an array of ArrayLists: ArrayList<Integer>[] arr=new ArrayList<Integer>[40]; there is an error and java does not allow this? Is there a reason related to ...
6
votes
4answers
256 views

Do functional generics exist and what is the correct name for them if they do?

Consider the following generic class: public class EntityChangeInfo<EntityType,TEntityKey> { ChangeTypeEnum ChangeType {get;} TEntityKeyType EntityKey {get;} } Here EntityType ...
6
votes
3answers
459 views

Why don’t UI frameworks use generics?

One way of looking at type safety is that it adds automatic tests all over your code that stop some things breaking in some ways. One of the tools that helps this in .NET is generics. However, both ...
6
votes
1answer
161 views

Using Type Parameter (or not)

Effective Java provides 2 ways to implement swap: // Two possible declarations for the swap method public static <E> void swap(List<E> list, int i, int j); public static void ...
5
votes
1answer
337 views

Why do generics in Scala have erased types, and are not reifiable?

Why do generics in Scala have erased types, and are not reifiable? Is it due to lack of support from the JVM or for compatibility with Java libraries? What are the advantages in general of having ...
5
votes
2answers
349 views

I don't know how to understand the Wildcard type in Java

I am reading the Core Java (9th edition) by Cay S. Horstmann and Gary Cornell. After making an effort, I cannot still understand the ? super Manager. Here are some materials relating to this question. ...
4
votes
3answers
421 views

Why is it so difficult to know where to use interfaces,generics in program design?

I am attempting to learn c# from the head first series, in addition i also consult other books such as Pro C# by Andrew Tolson. Now the thing is that i perfectly understand the interface,generics ...
4
votes
1answer
453 views

Using raw types in Java method signatures

In general I try to avoid using raw types in the signature of methods in the libraries I develop. However, lately I am starting to relax this (self-adopted) rule-of-thumb, and I am starting to write ...
4
votes
2answers
176 views

Understanding JAVA generic keyword 'super'

Recently some people said that I was wrong when I explained why one cannot insert a Number object into a list declared as List<? super RationalNumber>. (This assumes that RationalNumber is a ...
4
votes
1answer
392 views

Constraints while designing the Java generics

Java generics look quite different from those available in Scala, although both were designed by Martin Odersky. From my point of view, the design of generics in Java is worse, for instance: there ...
4
votes
3answers
263 views

generic programming- where did it originate?

Im trying to work out if generic programming was a functional programming feature which was then introduced into Java, C++ and C# or did the latter copy it from the functional programming languages ...
4
votes
3answers
334 views

Java - Use polymorphism or bounded type parameters

Suppose I have this class hierarchy... public abstract class Animal { public abstract void eat(); public abstract void talk(); } class Dog extends Animal { @Override public void eat() ...
4
votes
1answer
1k views

Why can't I implement an interface which has a bounded generic type in this code in java?

I have the following interfaces: public interface Successorable<E> extends Comparable<E> E suc(); } and interface IInterval <E extends Successorable<E>> { E min(); ...
4
votes
2answers
386 views

Java Generics - how to strike a balance between expressiveness and simplicity

I'm developing some code that utilizes generics, and one of my guiding principles was to make it usable for future scenarios, and not just today's. However, several coworkers have expressed that I may ...
3
votes
7answers
654 views

Protecting the uninitiated (developer) from generics

Is it acceptable to have a dummy generic parameter in the parameters list in order to save method consumers from the need to specify type arguments? For example - public T Generate<T>(int ...
3
votes
5answers
2k views

What problems can be solved using Generics?

I haven't used Generics in C# for a long while. Every time I think I need to use them I either go in the wrong direction and give up or find that I don't really need them. I feel that I'm missing out ...
3
votes
2answers
464 views

Need advice on framework design: how to make extending easy

I'm creating a framework/library for a rather specific use-case (data type). It uses diverse spring components, including spring-data. The library has a set of entity classes properly set up and ...
2
votes
1answer
227 views

Any programming languages that support Generics exclusively and have no OOP support? [closed]

I am writing a paper on the tension between OOP and Generic programming created by Stepanov. He widely criticizes OOP and says it is "technically flawed" when compared to Generic Programming. Now I ...
2
votes
1answer
2k views

Adding base-class (inherited) functionality to classes that you don't control

I have a set of classes from a 3rd party library. These classes use an inheritance structure to share logic. I would like to add a layer of abstraction in the middle of their inheritance tree to add ...
2
votes
2answers
88 views

Retried Operation with generic Exception

I am looking for a way to get the logic of retrying an operation in a single method while keeping the exception types of the operation. I.e., the implementation to retry an operation could look like ...
2
votes
3answers
1k views

Implementing multiple generic Interfaces in java

I've need an interface that assures me a certain method, including specific signature, is available. So far his is what I have: public interface Mappable<M> { M mapTo(M mappableEntity); } ...
1
vote
4answers
468 views

How to figure out design pattern for this particular solution?

While working on a project I've come up with some design solution. I am having a hard time relating it to any general design pattern or analyzing this situation in details. This is also prohibiting me ...
1
vote
1answer
146 views

Naming of type parameters in java

We all know that it is good to use descriptive identifier names. However, the convention in java is to use a single letter for a type parameter identifier. The default most people go to is T, but if ...
1
vote
4answers
622 views

Is absence of generic OrderedDictionary class in .NET framework really a design flaw?

I was absolutly sure that I need one (and some SO users too), but it turns out that my case was easily refactored with simple List<object>, and more I think about it I am no so sure anymore that ...
1
vote
1answer
157 views

How do I create a mutually-incompatible type library in Java?

Folks, this seems like it should be straightforward, but I'm drawing a blank here. As a simplified example, consider an abstract class called Number with an abstract method add(). I want to create ...
1
vote
1answer
79 views

Implement Generic DataSet Builder with C#

I want to create a data access library that can build a DataSets with relations which can easily be written to XML with dataset.WriteXML(). This is a get to know C# endeavor that will hopefully gain ...
0
votes
2answers
157 views

Similar references to themselves in two classes

How can I make 1 class (base, generic or something else) from these two classes? class A { A Link { get; set; } } class B { B Link { get; set; } } UPD: This is what I have now: class BSTree { ...
0
votes
1answer
638 views

Why it is not possible to Instantiating Types with Wildcards in Java

I am trying to instantiate LinkedList<?> op = new LinkedList<?>(); But I get error Cannot instantiate the type LinkedList<?> Why is it that this cannot be instantiated in Java? ...
0
votes
2answers
163 views

Question about casting a class in Java with generics

In Java 6 Class<? extends ArrayList<?>> a = ArrayList.class; gives and error, but Class<? extends ArrayList<?>> b = (Class<? extends ...
0
votes
1answer
128 views

Generics list without generics

I am using a very primitive Java that doesn't have Generics, and also I can't use reflection. I want to create a generic list so it would be typed safe (i.e. I only have a list that contains Objects ...
0
votes
0answers
32 views

Generic data import framework architecture

I'm refactoring a generic framework for importing data from a number of different sources. I'm struggling a bit with the design and I'd really appreciate some input. The importing process typically ...
0
votes
0answers
68 views

Use of raw types in Java XML-RPC

I have been investigating the implementation of XML-RPC in Java. The major open-source libraries (e.g. Apache XML-RPC) use raw types to represent certain XML-RPC types in Java, e.g. structs are ...
-1
votes
2answers
247 views

Generics vs IoC [closed]

One of the "Service Locator" pattern drawbacks is that a caller can be misleaded about dependencies of a callee. Ok, but what if I put dependencies as generic parameters at a class level: class ...