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

Type constraint on generic dictionary

I am using reflection to find a constructor of a given type. I then would like to cache the constructor keyed on its type so that I can use it on the fly the next time that constructor is needed. The code below does so but it requires me to store the...
more »

2017-10-04 20:10 (2) Answers

Integer type not working as expected (Java)

I'm writing one of my first programs dealing with generics and standard OOP principles in Java, however I am running into a bit of a problem when dealing with the Integer type. I noticed that Integers are expected to have a method named compareTo(In...
more »

2017-10-04 06:10 (1) Answers

Passing around generic classes in Dataflow

I'm using the Apache Beam version of Dataflow, and am currently running into an issue when I try to create a PTransform that outputs a generic class. Here's a minimal example of such a transform, which simply outputs a type repeatedly. public class ...
more »

2017-10-04 01:10 (1) Answers

Have I written a generic method?

submitButton.setOnAction(e -> totalPrice(Double.parseDouble(inputText.getText()), spinner.getValue())); The above statement runs the method below. Retrieves a numerical value that was entered in the gui input window, and whatever number the user...
more »

2017-10-03 18:10 (1) Answers

Passing around generic objects using an interface?

I'm building a tool to simply the exporting to excel for later re-use. One of the issues I'm running into is an easy, and reliable way of passing around an object that contains my cell data. The class that contains my cell data looks like: public i...
more »

2017-10-03 17:10 (1) Answers

Convert generic list into dataset in c#

Am having a method which returns Generic List from it . I Want to convert the list to DataSet in my code .Is there any built in method or there are any helper method available to convert into DataSet. Please Let me know. private string strPlantC...
more »

2017-10-03 13:10 (0) Answers

Swift generic protocol function with self

I have a generic class that conforms to a delegate protocol. I want to be able to pass self in the protocol methods, but I can't figure out how. protocol BodyPartManagerDelegate: class { func doit(manager: BodyPartManager<Any>) } class B...
more »

2017-10-03 06:10 (1) Answers

scala - using asInstanceOf with Generics

I'm having compilation issues with generics. The code compiles fine when I use asInstanceOf. I want to get rid of asInstanceOf. I saw some other questions related to the usage of asInstanceOf, but I didn't help me. trait RoundRobin[R <: Resourc...
more »

2017-10-03 05:10 (1) Answers

C# query a dictionary for unique generic objects

I am trying to write a generic method that returns a generic object. The method will take the generic type and use it to query a collection, for the object with the matching type. I have made an attempt but there is a compilation error, when trying ...
more »

2017-10-03 01:10 (1) Answers

Prove upper type bound for generic types

I have a type class which I'd like to use to store a type of an object: trait RetainType { type A } object RetainType { def apply[A0](): RetainType = new RetainType{ type A = A0 } } Given the following class: trait Annotation class Ent...
more »

2017-10-02 21:10 (1) Answers

Serialize response with switch on generic type

I'm using LitJson and BestHTTP libraries on a Unity3D project and I would write my custom ResponseSerializer object. The goal is create a method that uses generics to map the possible response into my wanted object. So, my first attempt was somethin...
more »

2017-10-02 12:10 (2) Answers

Comparing Object class to generic types

How can I compare the treeNodes to the generic type passed to the method? class TreeNode <E extends Comparable<E>> { Object data; TreeNode <E> leftChild; TreeNode <E> rightChild; public TreeNode(Object obj) ...
more »

2017-10-02 07:10 (0) Answers

Implementing custom Functional Interface in Java8

I am trying to implement a custom Functional Interface as below, but cannot get the correct syntax between the definition of the Functional Interface and the method which takes it as a parameter. Essentially, I have a method which I want to pass as ...
more »

2017-10-01 20:10 (0) Answers

C# enum as generic

Cheers! I had a two enums, describing my entityes: Players and guns types: public enum PlayersType { Scout, Tank } public enum GunsType { Machinegun, Tesla } I had a generic a struct generic class, and 2 realizations of it: publi...
more »

2017-10-01 13:10 (2) Answers