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

learn more… | top users | synonyms

1
vote
3answers
128 views

Advantage of generic base class

What's the advantage of having a generic base class and a derived class having itself as the generic parameter on the base class. e.g. public abstract class MyBase<T> {} public MyDerived : ...
4
votes
1answer
80 views

Lambda Return Type Inference

Writing my own JVM compiler, I am facing a giant problem that I am desperately unable to solve: Lambda Return Type Inference 1. Overview of the compiler lifecycle More specifically, the order in ...
1
vote
1answer
136 views

Should I use generics whenever possible or is object ok in some cases?

I'm having an interface ProgressReporter which basically takes a list of input items (the working queue) through a method SetWorkPackages(IEnumerable<T> workPackages) and then has another method ...
2
votes
1answer
152 views

Design pattern for ensuring the “signature” of generic lists is equal

I have an interface, Attribute, that is going to be implemented in various ways, class AttributeA implements Attribute{\\..} class AttributeB implements Attribute{\\..} Then I'm planning to have ...
1
vote
2answers
397 views

Generics in C# Test Class

I'm learning about unit testing in C#. Languages_Service and PlaceOfWork_Service are classes for SOAP services which Microsoft Navision generated for me. There are several methods that are very ...
12
votes
2answers
346 views

Is higher-rank parametric polymorphism useful?

I'm pretty sure everyone is familiar with generic methods of the form: T DoSomething<T>(T item) This function is also called parametrically polymorphic (PP), specifically rank-1 PP. Let's ...
12
votes
1answer
465 views

Why do you need higher kinds?

Some languages allow for classes and functions with type parameters (such as List<T> where T may be an arbitrary type). For example, you can have a function like: List<S> Function<S, ...
14
votes
3answers
2k views

What is the reason of using an interface versus a generically constrained type

In object-oriented languages that support generic type parameters (also known as class templates, and parametric polymorphism, though of course each name carries different connotations), it is often ...
3
votes
1answer
163 views

How to design similar purpose static methods

I know that you cannot override static functions, but for what I'm looking to do, it seems like the logical way to design my class. I have a method that is associated with my abstract class, that i ...
3
votes
2answers
361 views

Do wildcards in Java generics restrict or increase flexibility?

I have read many sources about wildcards and Java generics. Even though I have seen many explanations and answers, none of them seems correct. The question is very simple: Do wilcards in Java ...
2
votes
2answers
365 views

Is using generics to indicate some class/method is aware of a type good idea?

I'm going to use Java for code/idea demonstration. Imagine it's needed to define two interfaces: Observer and Observable (observer pattern). It's a good idea to have two generic interfaces, so there ...
4
votes
1answer
336 views

Using macros to implement a generic vector (dynamic array) in C. Is this a good idea?

So far I have only done personal projects at home. I hope to get involved in some open source project some time next year. The languages I that have been using the most are C and C++. I have used both ...
1
vote
1answer
277 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 ...
4
votes
1answer
146 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 ...
2
votes
2answers
400 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
32 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
201 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 ...
25
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 ...
4
votes
1answer
1k 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
118 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 ...
4
votes
3answers
357 views

@SuppressWarnings in generic array declaration

While doing a coding test, I ran into a problem where I need to initialize an array of generic type in Java. While trying to figure out how to do that, I looked at this Stack Overflow question and it ...
1
vote
1answer
122 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
369 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
1k 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
206 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 ...
6
votes
2answers
989 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
361 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
3k 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
414 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
2k 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
302 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 ...
11
votes
2answers
1k 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
154 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
203 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
3answers
2k 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
195 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
293 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
962 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
3k 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); } ...
13
votes
3answers
1k 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
472 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
544 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
4k 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
171 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
165 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 { ...
1
vote
1answer
2k 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
6k 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 ...
6
votes
2answers
479 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
481 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
578 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 ...