Just a thought.
Wouldn't it be useful to have optional type parameters in C#?
This would make life simpler. I'm tired of having multiple classes with the same name, but different type parameters. Also VS doesn't support this very vell (file names) :-)
This would for example eliminate the need for a non-generic IEnumerable:
interface ...
I saw some code on an unrelated question but it got me curious as I never saw such construct with Java Generics. What would be the use of creating a generic class that can take as type argument itself or descendants of itself. Here is example :
abstract class A<E extends A<E>> {
abstract void foo(E x);
}
the first thing that cam...
Suppose that I have created a method like this
private void Test<t>(t str)
{
}
Now from another method i call it
private void BtnClick()
{
string a = "";
test<Here I Want To assign The Type what ever the type of 'a' is>();
}
How can I do this ?
...
I want to create a class that takes two parameters. One should be typed simply as T. The other should be typed as something that extends both T and SomeInterface<T>. When I attempt this with
public class SomeClass<T, S extends SomeInterface<T> & T>
then Java complains with
"The type T is not an interface; it cannot be specified a...
Hi.
I have seen different questions regarding this, but I still find this topic to be very confusing.
All I want to do, is have an abstract class that implements an interface, and have a class extending this abstract class so that the hard class needs to implement getKommune() and setKommune(Kommune kommune), but not the other method, ...
This question is sort of a follow-up to my original question here.
Let's say that I have the following generic class (simplifying! ^_^):
class CasterClass<T> where T : class
{
public CasterClass() { /* none */ }
public T Cast(object obj)
{
return (obj as T);
}
}
Which has the ability to cast an object into a s...
The structure I am trying to achieve is a composite Dictionary key which is item name and item displayname and the Dictionary value being the combination of n strings
So I came up with
var pages = new Dictionary<string[], StringBuilder>()
{
{ new string[] { "food-and-drink", "Food & Drink" }, new StringBuilder() },
{ new string...
The compiler, given the following code, tells me "Use of unassigned local variable 'x'." Any thoughts?
public delegate Y Function<X,Y>(X x);
public class Map<X,Y>
{
private Function<X,Y> F;
public Map(Function f)
{
F = f;
}
public Collection<Y> Over(Collection<X> xs){
List<Y> ys = new List<Y>();
...
I want to implement a generic method on a generic class which would allow to cast safely, see example:
public class Foo<T> : IEnumerable<T>
{
...
public IEnumerable<R> SafeCast<R>()
where T : R
{
return this.Select(item => (R)item);
}
}
However, the compiler tells me that Foo<T>.SafeCast<R>() does not d...
Is there a way in java to have a ListModel that only accepts a certain type?
What I'm looking for is something like DefaultListModel<String> oder TypedListModel<String>, because the DefaultListModel only implements addElement(Object obj) and get(int index) which returns Object of course.
That way I always have to cast from Object to e....
I am trying to create a method that accepts multiple types of controls - in this case Labels and Panels. The conversion does not work because IConvertible doesn't convert these Types. Any help would be so appreciated.
Thanks in advance
public void LocationsLink<C>(C control)
{
if (control != null)
{
Web...
i think this is a simple question but I've searched around and can't seem to find an answer easily.
if you have
var list = List<int>();
... fill list ...
and you want to get the generic type in list, i realise you could just type:
var t = list.FirstOrDefault().GetType();
Is there another way to do this via just the list, rather th...
ok, i found some similar posts on stackoverflow, but I couldn't find any that pertained to my exact situation and I was confused with some of the answers given. Ok, so here is my problem:
I have a template matrix class as follows:
template <typename T, size_t ROWS, size_t COLS>
class Matrix
{
public:
template<typename, ...
I have some C structures related to a 'list' data structure.
They look like this.
struct nmlist_element_s {
void *data;
struct nmlist_element_s *next;
};
typedef struct nmlist_element_s nmlist_element;
struct nmlist_s {
void (*destructor)(void *data);
int (*cmp)(const void *e1, const void *e2);
unsigned int size;
...
I have a class that inherits from a generic dictionary as follows:
Class myClass : System.Collections.Generic.Dictionary<int, Object>
I have added a list of values to this in a particular order, but I now wish to change that order. Is there any way (without removing and re-adding) that I could effectively re-index the values; so chan...
Hi,
I get an IEnumerable which I know is a object array. I also know the datatype of the elements. Now I need to cast this to an IEnumerable<T>, where T is a supplied type. For instance
IEnumerable results = GetUsers();
Type t = GetType(); //Say this returns User
IEnumerable<T> users = ConvertToTypedIEnumerable(results, t);
I now wan...
Let's say I have this:
val myAnon:(Option[String],String)=>String = (a:Option[String],defVal:String) => {
a.getOrElse(defVal)
}
Don't mind what the function does. Is there anyway of making it generic, so I can have an Option[T]?
...
Let's say I had:
protected void performLogic(List<Object> docs) {
...
}
In the code where I'm going to be calling this method, I have a List<String> list. I want to call performLogic, passing this list. But it won't work because the lists are 2 different types:
public void execute() {
List<String> docs = new ArrayList<String>()...
I have a generic class that takes a type T. Within this class I have a method were I need to compare a type T to another type T such as:
public class MyClass<T>
{
public T MaxValue
{
// Implimentation for MaxValue
}
public T MyMethod(T argument)
{
if(argument > this.MaxValue)
{
...
In this example from the App Engine docs, why does the example declare contactInfos like this (no Generics):
import javax.jdo.annotations.Element;
// ...
@Persistent
@Element(dependent = "true")
private List contactInfos;
instead of like this, using a Generic:
import javax.jdo.annotations.Element;
// ...
@Persistent
...