Here is what I am trying to do:
private readonly IDictionary<float, ICollection<IGameObjectController>> layers;
foreach (ICollection<IGameObjectController> layerSet in layers.Values)
{
foreach (IGameObjectController controller in layerSet)
{
if (controller.Model.DefinedInV...
What is the correct type of argument to the addAll(..) method in Java collections? If I do something like this:
List<? extends Map<String, Object[]>> currentList = new ArrayList<Map<String, Object[]>>();
Collection<HashMap<String, Object[]>> addAll = new ArrayList<HashMap<String, Object[]>>();
// add some hashmaps to the list..
currentL...
I'm trying to store a list of generic objects in a generic list, but I'm having difficulty declaring it. My object looks like:
public class Field<T>
{
public string Name { get; set; }
public string Description { get; set; }
public T Value { get; set; }
/*
...
*/
}
I'd like to create a list of these. My problem...
The question more or less says it all. Given the following record structure:
type
TPerson = record
Name: string;
Age: Integer;
end;
PPerson = ^TPerson;
TPersonList = TList<TPerson>;
Is the following code valid?
procedure ReadPeople(DataSet: TDataSet; PersonList: TPersonList);
begin
PersonList.Coun...
I've been trying to make my way through this article:
http://blogs.msdn.com/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx
... And something on page 1 made me uncomfortable. In particular, I was trying to wrap my head around the Compose<>() function, and I wrote an example for myself. Consider the following two Func's:
Func<d...
I have an interface like this
public interface IField<T> extends IsSerializable {
public String getKey();
public void setKey(String name);
public T getValue();
public void setValue(T role); }
And a class like this
public class FieldImpl<T> implements IField<T> {
private String key;
public String getKey() {
return key;
}
public...
I'm relatively new to Java and am used to generics in C# so have struggled a bit with this code. Basically I want a generic method for getting a stored Android preference by key and this code, albeit ugly, works for a Boolean but not an Integer, when it blows up with a ClassCastException. Can anyone tell me why this is wrong and maybe he...
I'm creating a generic list class that has a member of type Array(Array of ).
The problem is the class destruction,because the class is supposed to be used for types from byte to types inheriting TObject.
Specifically:
destructor Destroy;
var elem:T;
begin
/*if(T is Tobject) then //Check if T inherits TObject {Compiler error!}
f...
Consider the following declaration of a generic utility class in Delphi 2010:
TEnumerableUtils = class
public
class function InferenceTest<T>(Param: T): T;
class function Count<T>(Enumerable: TEnumerable<T>): Integer; overload;
class function Count<T>(Enumerable: TEnumerable<T>; Filter: TPredicate<T>): Integer; overload;
end;
So...
I am using javax.validation.Validator and relevant classes for annotation based validation.
Configuration<?> configuration = Validation.byDefaultProvider().configure();
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<ValidatableObject>> const...
I'm having problems creating a collection of delegate using reflection and generics.
I'm trying to create a delegate collection from Ally methods, whose share a common method signature.
public class Classy
{
public string FirstMethod<T1, T2>( string id, Func<T1, int, IEnumerable<T2>> del );
public string SecondMethod<T1, T2>( strin...
That is the question. What I want to accomplish is something similar to the following Java code:
class A { }
class B extends A { }
public class Tests {
public static void main(String [] args) {
ArrayList<? extends A> lists = new ArrayList<B>();
}
}
(in which B extends A means B inherits from A)
Is it possible at all...
I am from a Java background and I am looking from the equivalent in c# for the following.
public interface Reader {
<T> T read(Class<? extends T> type);
}
Such that I can do the following, constraining the parameter and inferring the return type.
Cat cat = reader.read(Cat.class);
Dog dog = reader.read(Dog.class);
I was hoping so...
The problem:
class StatesChain : IState, IHasStateList {
private TasksChain tasks = new TasksChain();
...
public IList<IState> States {
get { return _taskChain.Tasks; }
}
IList<ITask> IHasTasksCollection.Tasks {
get { return _taskChain.Tasks; } <-- ERROR! You can't do this in C#!
...
This code generates a compiler error that the member is already defined with the same parameter types.
private T GetProperty<T>(Func<Settings, T> GetFunc) where T:class
{
try
{
return GetFunc(Properties.Settings.Default);
}
catch (Exception exception)
{
SettingReadE...
Hello everyone, this morning I came across this code, and I have absolutely no idea what that means. Can anyone explain me what do these <T> represent? For example:
public class MyClass<T>
...
some bits of code then
private Something<T> so;
private OtherThing<T> to;
private Class<T> c;
Thank you
...
Why Generics (in Java) works with the objects but not with primitive types?
For example
Gen<Integer> inum = new Gen<Integer>(100); // works fine, but
Gen<int> inums = new Gen<int>(100); // is not allowed.
Thanks !
...
Hi,
I came across PECS (short for Producer extends and Consumer super) while reading on Generics.
Can someone explain to me how to use PECS to resolve confusion between extends and super?
Thanks in advance!
...
I have some entities created with LINQ-to-SQL. Six of these entities (representing values primarily in drop-down lists) implement an interface I've called IValue. I did this because the UI layer is going to have to account for a couple special cases -- notably, what to display if the original value on a record has been flagged as deleted...
Having defined this interface:
public interface IInputBoxService<out T> {
bool ShowDialog();
T Result { get; }
}
Why does the following code work:
public class StringInputBoxService : IInputBoxService<string> {
...
}
...
IInputBoxService<object> service = new StringInputBoxService();
and this doesn't?:
public class I...