Hello,
In simple words, I want to implement a function like that:
let myfunction (scalar : float) (quantities : ''T list) =
List.fold (fun acc quantity -> acc + quantity * scalar)
LanguagePrimitives.GenericZero<_>
quantities : 'T
Note that I am multiplying a value of generic type 'T and a float value (quantit...
While f1 does compile, the very similar f2 wont I and just cant explain why.
(Tested on Intellij 9 and Eclipse 3.6)
And really I thought I was done with that kind of question.
import java.util.*;
public class Demo {
public List<? extends Set<Integer>> f1(){
final List<HashSet<Integer>> list = null;
return list; ...
I have looked at a lot of example c# generic code and remember seeing a syntactic declaration trick that created an alternative shorthand type for a long generic dictionary type. Mixing C# and C++ it was something like:
typedef MyIndex as Dictionary< MyKey, MyClass>;
This then allowed the following usage:
class Foo
{
MyIndex _cla...
Hello :)
I am trying to do the following in C# 4.0:
I have a Base Class and 2 derived classes
public class Base {}
public class DerivedClass1 : Base {}
public class DerivedClass2 : Base {}
I want to do something like this, but it doesn't work.
How to I tell a Generic List to accept a Base Class and the derived classes of the bas...
Hi! What does new() mean in the following context:
public interface ISpecification<TEntity>
where TEntity : class,new()
...
Is it possible to construct an object with its internal constructor within a generic method?
public abstract class FooBase { }
public class Foo : FooBase {
internal Foo() { }
}
public static class FooFactory {
public static TFooResult CreateFoo<TFooResult>()
where TFooResult : FooBase, new() {
return new TFooResult(...
Hello,
I am recently working on a C# class library implementing an algorithm. The point is that I would like the users of the library to be able to choose the machine precision (single or double) the algorithm should operate with, and I'm trying to do it with generics. So, for instance:
Algorithm<double> a = new Algorithm<doubl...
I am trying to do one of the following:
Dummy d = (Class<Dummy>)super.getEntity(); // incompatible Types - cannot cast
Dummy d = (Dummy)super.getEntity(); // incompatible Types - cannot cast
d.foo();
or
Class<Dummy> d = (Class<Dummy>)super.getEntity(); // works
d.foo(); // method cannot be found
Dummy d is defined in an abstract ...
I've heavily simplified my problem. Here's how it reads.
I'm trying to figure out why the following code does not compile:
List<AnonType<AnonType<?>>> l = new ArrayList<AnonType<AnonType<?>>>();
l.add( new AnonType<AnonType<String>>() );
where
public class AnonType<T> {
T a;
List<T> b;
}
The compiler error is saying that ad...
I would like to convert T to T[] if it is an array.
static T GenericFunction<T>(T t)
{
if (t == null) return default(T);
if (t.GetType().IsArray)
{
//if object is an array it should be handled
//by an array method
return (T) GenericArrayFunction((T[])t);
}
...
}
s...
Suppose you have an interface like this:
public interface IDoSomething<out T>
{
T DoSomething(object value);
}
To be able to call DoSomething on that interface without knowing the type of T, you have to create this:
public interface IDoSomething
{
object DoSomething(object value);
}
Modify your original interface to inherit...
Hi,
When I'm writing this code, I've got a Compile error in Scala
var s: Stack[_ <: Number] = new Stack[Integer];
s.push(new Integer(1)); //compile-error: type mismatch; found :Integer required: _$bqjyh where type _$bqjyh <: Number
s.push(null); //compile-error: type mismatch; found : Null(null) required: _$2 where type _$2 <: Objec...
Hi,
In C# it's possible to defined a method parameter with two interface restrictions. This with bounds. For example.
interface IA
{
int A {get;}
}
interface IB
{
int B {get;}
}
void Foo<T>(T param1) where T: IA, IB {}
So two interfaces, and the first parameter (param1) of the method Foo should implement both interfaces.
But ...
Hi, I'm working on an engine which is meant to be configurable by the user (not end user, the library user) to use different components.
For example, let's say the class Drawer must have an ITool, Pencil or Brush, and an IPattern, Plain or Mosaic. Also, let's say a Brush must have an IMaterial of either Copper or Wood
Let's say the effe...
Hello!
How to find out if object supports IHandle<T> and is there any possible workaround to achieve this in delphi (2010, XE)? Also has anybody seen a nice implementation of event aggregator for delphi?
IHandle<TMessage> = interface
procedure Handle(AMessage: TMessage);
end;
EventAggregator = class
private
FSubscribers: TList<TObj...
I have the following line in some of my haxe code:
removeChild(_screens[Helpers.indexOf(_screenNames, _activeScreen)]);
(_screens is a List, GameScreen is extending from Sprite, _activeScreen is a String, _screenNames is a List, and Helpers.indexOf does the obvious)
However, i get the error:
List<com.haxelib.GameScreen> should be Ar...
public class MyClass<T>
{
public T this[int index]
{
get
{
...
}
set
{
...
}
}
public void MyMethod<T>()
{
int middleIndex = ...;
T value = this[middle...
I have created a TreeMap like so:
TreeMap<Integer, ArrayList<MyClass>> wrap = new TreeMap<Integer, ArrayList<MyClass>>();
I have created a constructor like so:
public foo (TreeMap<Integer, Collection<Spot> > objects) {
this.field = objects;
}
However, eclipse gives me a red squigly when I use the constructor, with my wrap vari...
I am trying to create a static entry to a bunch of non-static util methods and getting this error with the sun compiler that I am not getting in eclipse:
"type parameters of X cannot be determined; no unique maximal instance exists for type variable X with upper bounds X,java.lang.Object"
public class Resource {
protected <X> X from...
I've got these interfaces:
And this code:
IList<IFinder<IDomainObject>> finders = new List<IFinder<IDomainObject>>();
IFinder<IOrder> orderFinder = this.mocks.StrictMock<IFinder<IOrder>>();
finders.Add(orderFinder);
I get this error on the third line:
Argument '1': cannot convert from 'Mes.FrameworkTest.Repository.Finders.IFind...