how to create generic parametric arrays

Considering this following class public class Pair <T, U> { public T first ; public U second ; public Pair (T first , U second ) { this . first = first ; this . second = second ; } } Write the method public static <T, U&...
more »

2017-10-04 23:10 (0) Answers

How to write lambdas with generics in kotlin?

I can write lambdas id_Int and id_Boolean with explicit type. And I can write function identity with type parameter. Can I write lambdas with type parameter? fun testFuncInt(f: (Int) -> Int): Int = f(1) + 2 val id_Int = { x: Int -> x } fun t...
more »

2017-07-03 09:07 (3) Answers

Nested Generic Type Parameters Parameters

I have an abstract class which is defined as: public abstract class BaseClass<T extends FirstClass, U extends BaseAnother<? extends SecondClass>> { I don't wanna use question mark (?) and use some generic variable as like T or U. How...
more »

2017-01-19 17:01 (1) Answers

Java Generics: "Nested" type parameters?

EDIT: Yes, this may be a duplicate. But whereas the other question is akin to "What is a chainsaw and how do I use it?" mine is more like "I am trying to drill a hole with this machine here and it doesn't work - what's up?". Of course the answer is "...
more »

2016-11-02 13:11 (1) Answers

Capturing type parameter in anonymous class

I would like to dynamically create a class which implements a given given interface and binds a type parameter of that interface. That's my interface definition: public interface Container<T> {} My initial thought was to use an anonymous cla...
more »

2016-10-06 10:10 (0) Answers

Issue with Java type parameters for return values

I've tried to condense this issue down to the smallest amount of code that I could. I have defined a table structure, like a database table, with the Row and Table classes below. A Table is essentially a list of Row. I want subclasses to define th...
more »

2016-10-05 23:10 (2) Answers

Write function with type parameter

I have a unit test, which test some solution. But this test code can also be applied for testing the other, very similar solution. What I want to make is code of test be generic to be applied to both solutions, like this: describe("when table contai...
more »

2016-09-30 14:09 (2) Answers