Hello!
This code is simplified as much as I can from a more complex class structure. In the real code, there were sub-types of the Integer and Double types I use here.
I'm trying to use Java Generics with a type parameter. If the user requests the type of Number.class, we want to combine the List<Integer> list and the List<Double> list...
namespace MyNamespace
{
public struct MyStruct
{
public string MyString;
public int MyInt;
public bool MyBool;
}
public class MyClass
{
private List<MyStruct> MyPrivateVariable;
public List<MyStruct> MyVariable
{
get
{
if (MyPriv...
Is it possible to do something like this in Scala:
class MyTest {
def foo[A <: String _or_ A <: Int](p:List[A]) = {}
}
That is, the type A could be a String or Int. Is this possible?
(Similar question here)
...
Imagine type like this (C#):
public interface IAmGeneric<T>
{
void SoAmI<T1>(T one, T1 two);
}
Given I have open generic MethodInfo from open generic version of the type (IAmGeneric<>.SoAmI<>()) and the following array
new[] { typeof(int), typeof(string) }'
I'm looking for well performing and reliable way of getting closed versi...
I'm reading data from a custom data format that conceptually stores data in a table. Each column can have a distinct type. The types are specific to the file format and map to C# types.
I have a Column type that encapsulates the idea of a column, with generic parameter T indicating the C# type that is in the column. The Column.FormatTyp...
The following code is an example of a factory that produces a Bar<T> given a Foo<T>. The factory doesn't care what T is: for any type T, it can make a Bar<T> from a Foo<T>.
import com.google.inject.*;
import com.google.inject.assistedinject.*;
class Foo<T> {
public void flip(T x) { System.out.println("flip: " + x); }
}
interface Ba...
This code is returning me a list that I am trying to pass to another function.
_ucItem.lblItemName.Text = itemRow.Field<string>("ITEM_NAME").ToString();
_ucItem.pbxItemImg.Image = itemRow.Field<string>("IMAGE").ToString();
_ucItem.lblItemName.Text = itemRow.Field<string>("FK_ITEM_ID").ToString();
Here I want to replace this set of lin...
I want to write a generic function that has a constraint on the type. Specifically I want something like this:
bool IsInList<T>(T value, params T[] args)
{
bool found = false;
foreach(var arg in args)
{
if(arg == value)
{
found = true;
break;
}
}
return found;
}
The ...
I wonder if it is possible to define a generic C++ container that stores items as follows:
template <typename T>
class Item{
typename T value;
}
I am aware that the declaration needs the definition of the item type such as:
std::vector<Item <int> > items;
Is there any pattern design or wrapper that may solve this issue?
...
I have the following class & interface defined:
public interface A {
}
public class B implements A {
}
I have a List of B objects that I need to cast to a List of A objects:
List<B> listB = new List<B>();
listB.add(new B()); // dummy data
listB.add(new B()); // dummy data
listB.add(new B()); // dummy data
List<A> listA = (List<A>...
I need to create a dictionary that has 2 values per key, it must return one of the 2 values with the same probability.
Example:
myDicry
{
key = "A", value1=15, value2=56;
}
int firstCall = myDicry["A"]; // = 15
int secondCall = myDicry["A"]; // = 56
...
I want to have a method which calculates the mean of a LinkedList of type Integer, Double and Float.
The problem is the sum += i; statement, since java says that the + operator isn't defined for type Object.
I could do a cast, but if the LinkedList was of type Float, for example, and the cast was to Integer, I would be not computing ...
Hi. I need you to review my implementation of a Singly Linked List (SLL) please. The implementation should use generics and be able to use the enhanced for.
The problem is that, when I do for (Number n : list) being list a MyLinkedList<Integer> or MyLinkedList<Double>, I get the error: "Type mismatch: cannot convert from element type O...
Is there a way to apply several different csharp generic constraints to the same type where the test is OR rather than AND?
I have an extension method I want to apply to a subset of an interface, but there is no common interface or base class that only captures the classes I wish to target.
In the example below, I could write multiple ...
I have an abstract generic class.
public abstract class FieldHandlerWithData<DataType extends Parcelable>
extends FieldHandler
Now I have an object c
Class<? extends FieldHandler> c = getHandlerClass(type);
and now I want to test if c inherits FieldHandlerWithData (directly or indirectly).
How to determine whether c inherits F...
I have some code generated from xsd files by xmlbeans-maven-plugin. Unfortunately generated code uses raw collection types, like:
java.util.List targetList = new java.util.ArrayList();
get_store().find_all_element_users(CURRENCY$0, targetList);
Currency[] result = new Currency[targetList.size()];
targetList.toArray(result);
which caus...
In Java I have a class tha has a payload of type T
public class GenericStatus<T> {
private MyDateRange myDateRange;
private T payload;
At runtime T can be either a simple primitive Integer or a class called Price where Price is a class with 2 integers
public class Price implements Serializable {
private int adult;
priva...
Hi folks,
I'm a newbie in Java so I'm not sure if this is possible. Basically I need to de-serialise a file into an object of a given type. Basically the method will do this:
FileInputStream fis = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fis);
MyClass newObject = (MyClass)in.readObject();
...
Hi Everyone,
I'm writing some Enum functionality, and have the following:
public static T ConvertStringToEnumValue<T>(string valueToConvert,
bool isCaseSensitive)
{
if (String.IsNullOrWhiteSpace(valueToConvert))
return (T)typeof(T).TypeInitializer.Invoke(null);
valueToConvert = valueToConvert.Replace(" ", "");
...
I have this code behind:
CustomUserControl.xaml.cs
namespace MyProject
{
public partial class CustomUserControl<T> : UserControl
{
...
}
}
and this xaml:
CustomUserControl.xaml
<UserControl x:Class="MyProject.CustomUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
x...