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

learn more… | top users | synonyms

1
vote
1answer
55 views

OK to make a method generic just to pass in a System.Type?

Sometimes I have a function that takes a System.Type parameter, like: public void Foo(Type type) { // do something with "type" ... } This must be called like this: Foo(typeof(MyType)); I ...
1
vote
0answers
53 views

Extend, wrap, or both to add generics to a class that should have had them?

So I'm using a C# framework that has a great example of where generics would be useful, except they weren't used. For simplicity's sake, we will say it was a list (I know C# has its own list), but ...
1
vote
2answers
362 views

Generics in low level languages

I'm developing a language like Vala and OOC that compiles back to C. This means that, eventually, every feature needs to be adoptable to C code in some way or another. Generics is one of the features ...
0
votes
0answers
27 views

Restructuring similar interfaces to one unified design

In my project, I have several types of Web API controllers (and their corresponding services and repositories). When I started out, I made an interface of a generic type that would describe the basic ...
0
votes
3answers
143 views

Why static members can't be abstract and don't implement polymorphism? [duplicate]

I'm a Java/C#/PHP developer, through my OOP programming experience I find myself asking the same question: Why static members can't be abstract and don't implement polymorphism especially in ...
23
votes
3answers
2k views

A good generic type system

It's commonly accepted that Java generics failed in some important ways. The combination of wildcards and bounds led to some seriously unreadable code. However, when I look at other languages, I ...
2
votes
1answer
226 views

What are the main differences between C++ templates and Java generics? [closed]

I'm a beginning C++ programmer coming from Java. It feels to me that C++ templates and Java generics are actually pretty similar. You use them in pretty much the same occasions and in the same way. ...
1
vote
2answers
63 views

Class template specialization for implementing Automata

I'm implementing classes for simulating and generating different kind of automata. I'd prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc. For a PDA a ...
1
vote
1answer
102 views

Ignoring the generic part of a type while an object is being passed

I have a message class that holds the name of a destination, and a generic variable acting as the message payload public class Message<T> { public string Destination public T Payload ...
3
votes
2answers
261 views

Parameterized Java Types (Generics)

Consider this "legacy" code: public interface IPersistentCollection { IPersistentCollection cons(Object o); } Genericized in Java, it could become something like this: public interface ...
4
votes
3answers
535 views

Implementing a generic/dynamic custom property system in C#

I have an architecture design problem which I think is appropriate for this site. Note that I have made an EDIT to this post below, reflecting my latest potential solution to this problem. General ...
2
votes
3answers
182 views

How to use Option Type Pattern in a language that doesn't support generics?

I've been interested to start using the Null Object / Option Type approach for replacing my old habits of null-checking multiple parts of my code. But, from the many examples I saw out there, it seems ...
5
votes
2answers
354 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 ...
1
vote
1answer
211 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 ...
34
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 ...
5
votes
2answers
379 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. ...
0
votes
2answers
514 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 ...
3
votes
2answers
172 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 ...
10
votes
2answers
506 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) ...
0
votes
1answer
138 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 ...
5
votes
1answer
173 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
775 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
166 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
246 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
658 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 ...
2
votes
3answers
2k 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); } ...
11
votes
2answers
590 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
337 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
491 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
3k 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
162 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
159 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
1k 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
3k 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 ...
5
votes
2answers
435 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
442 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
480 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 ...
13
votes
1answer
1k 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
391 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
263 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
569 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 ...
5
votes
1answer
450 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 ...
25
votes
1answer
5k 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?
6
votes
3answers
489 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
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(); ...
10
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
8k 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
671 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
289 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 ...