Deep copying Generics in Java

I have a programming assignment to make a generic stack in Java and I need to make a deep copy of newNode T. I don't know how to make a method deep Copy that can access its self and output i'`s deep copy. So far, I have this: public class Stack<...
more »

2017-03-19 03:03 (1) Answers

How do I handle a generic field in JaxB?

I have a parameterized class with a generic field like this and I'm trying to figure how how to write an adapter that will handle the generic field: public class Thing<T> { private T options; @XmlElement(nillable = true) @XmlNull...
more »

2017-03-18 17:03 (0) Answers

Passing Parameters to C# Generic Method

I had recently created a function to make loading multiple classes, while benchmarking the loading time easier with a simple method. I would like to know how I can extend this to allow multiple parameters passed to the method itself, and multiple par...
more »

2017-03-18 14:03 (0) Answers

Linked list Generics java

So i just started learning about java generics and my teacher gave us this code public class LinkedList<T> { class Node<T>{ T info; Node<T> next; } Node<T> head = new Node<T>(); /* and here...
more »

2017-03-17 11:03 (5) Answers

Covariance in inheritance

I have a super class SheetBuilder and many sub classes that inherit this class. The super class has an abstract method that all the classes inherit. protected abstract void printResults(String abc); Now I want to overload the same method with a d...
more »

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

Custom default value for generic parameter

I'm trying to write a generic method to read data from SQLDataReader. It works really well except when I want to get custom default value for some data types. For example, for string I want to get string.Empty instead of null. public static T SafeGe...
more »

2017-03-16 22:03 (4) Answers

Generic object updater - convert array to list

I'm trying to make a generic class, which is capable to update any property of an object. I made it working for several cases, e.g. single value properties (int, string, bool, etc.). It also works nicely if a property is an IEnumerable<T>, in...
more »

2017-03-16 22:03 (1) Answers

return generic type from java method

I want my Java method to return a generic T. I can't get it to work. My method executes a passed in method on a threadpool executor and waits for the result via a Future.get(), I want to pass the result back and this result can be different dependi...
more »

2017-03-16 20:03 (1) Answers

Scala reflection type equality of generic wildcard

I'm trying to test equality between a vector of generic types and a list of input parameters to a case class constructor. I've figured out how to use reflection to get the list of parameter and their types, but I can't figure out how to test for equa...
more »

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

Java use of ? in generic programming

Consider these 2 instance functions: public <T> void f1 (List<? extends Object> a) { System.out.println(a); } public void f2 (<? extends Object> a) { System.out.println(a); } The first function is accepted while the...
more »

2017-03-16 13:03 (2) Answers