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

learn more… | top users | synonyms

0
votes
1answer
115 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 ...
6
votes
1answer
152 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 ...
4
votes
3answers
255 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() ...
1
vote
1answer
133 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 ...
2
votes
1answer
214 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 ...
4
votes
1answer
346 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 ...
0
votes
0answers
63 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 ...
2
votes
3answers
608 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); } ...
9
votes
2answers
442 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 ...
-1
votes
2answers
220 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 ...
1
vote
4answers
452 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 ...
2
votes
1answer
1k 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 ...
1
vote
1answer
154 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 ...
0
votes
2answers
156 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
448 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? ...
3
votes
5answers
1k 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 ...
4
votes
2answers
367 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 ...
4
votes
3answers
412 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 ...
6
votes
1answer
382 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 ...
12
votes
1answer
805 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: ...
5
votes
1answer
317 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 ...
6
votes
4answers
252 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 ...
3
votes
2answers
427 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 ...
3
votes
1answer
342 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 ...
22
votes
1answer
3k 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?
5
votes
3answers
436 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 ...
4
votes
1answer
853 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(); ...
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 ...
8
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: ...
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 ...
3
votes
7answers
645 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 ...
4
votes
3answers
254 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 ...
8
votes
3answers
6k 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
372 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 ...
9
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 ...
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 ...
0
votes
4answers
603 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 ...
4
votes
6answers
1k views

How do I pronounce generic type names that contain backtick characters?

Given this type name: System.Nullable`1 How does the backtick character influence the pronunciation of this type name in its entirety? Put another way, how do I fluently pronounce that type name? ...
35
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 ...