In Java, am I able to extend from a generic supertype? According to this article, it looks like I should be able: http://www.ibm.com/developerworks/java/library/j-djc05133.html.
However, when I do something similar in my application, I get the following error: "Cannot refer to the type parameter T as a supertype."
Does anyone know if I...
In a window of my WPF application I have several hundreds of objects, they based on a custom control. They differ from each other only by name:
...
<MyNamespace:MyCustControl x:Name="x4y3" />
<MyNamespace:MyCustControl x:Name="x4y4" />
<MyNamespace:MyCustControl x:Name="x4y5" />
<MyNamespace:MyCustControl x:Name="x4y6" />
<MyNamespace:M...
This is the exact same question as this one: “Could not find type” error loading a form in the Designer
Before anyone goes closing my question please read that one. You will realize that it did not get a real answer. I hope to get a full answer (rather than a workaround) from this question.
When I create a class that descends from Co...
Hi
I would like to convert List<Company> to List<ICompany>
ICompany is an interface which Company implements.
public List<ICompany> FindAll()
{
List<Company> companies = new List<Company>();
var query = from c in _scope.Extent<Company>()
select c;
companies = query.ToList();
return companies.ToList<I...
Is it possible to do something like this in C#:
public void DoSomething<T>(T t)
{
if (T is MyClass)
{
MyClass mc = (MyClass)t
...
}
else if (T is List<MyClass>)
{
List<MyClass> lmc = (List<MyClass>)t
...
}
}
...
This is a syntax question. I have a generic class which is inheriting from a generic base class and is applying a constraint to one of the type parameters. I also want the derived class to implement an interface. For the life of me, I cannot seem to figure out the correct syntax.
This is what I have:
DerivedFoo<T1,T2> : ParentFoo<T1, T...
I wrote ASP.NET pages which will manage forms. They're based on the following base class.
public abstract class FormPageBase<TInterface, TModel> : Page, IKeywordProvider
where TModel:ActiveRecordBase<MasterForm>, TInterface, new()
where TInterface:IMasterForm
{
public TInterface FormData { get; set; } ...
Hi,
The following Groovy code prints "it works"
def printIt(Class<? extends Exception> clazz) {
println "it works"
}
printIt(String.class)
even though the parameter doesn't satisfy the constraint Class<? extends Exception>
My understanding is that this is because:
Type erasure in Java generics means there's no run-time generic...
Imagine the following method
public void SomeMethod<T>(T param)
where T: List<T2>
{
}
It doesn't work:
Error 16 The type or namespace name 'T2' could not be found (are you missing a using directive or an assembly reference?)
How do I achieve the what I clearly intended to do?
...
For the sake of this question, here is my generic class.
[ComVisible(true)]
public class HtmlTable<T> where T : class
{
List<T> listToConvert;
public HtmlTable(List<T> listToConvert)
{
this.listToConvert = listToConvert;
}
}
Essentially, this class is responsibly for converting a List of class T to an HTML tab...
Hello, I am trying to implement an inner class that has generic parameterized type.
Here is my code (short version):
public class AVLTree<T extends Comparable<? super T>> implements Iterable<T> {
...
private class BinaryNode<T extends Comparable<? super T>> {
...
}
private class TreePreOrderIterator<E extends Comparable<? super...
If I write a generic class like class MyGeneric<T> is it possible to write an implicit cast to type T, so I can do stuff like:
public class MyGeneric<T>
{
...
}
public class GenericProperties
{
public MyGeneric<string> MyGenericString {get;set;}
public void UseMyGeneric()
{
string sTest = MyGenericString;
MyGene...
I've run into a sticky problem that I can't seem to solve with java generics. This is a bit complicated, but I couldn't think of a simpler scenario to illustrate the problem... Here goes:
I have a Processor class that requires a Context. There are different types of Context; most processors just need any abstract Context, but others ...
Take the following:
public Class<List<String>> getObjectType() {
// what can I return here?
}
What class literal expression can I return from this method which will satisfy the generics and compile? List.class won't compile, and neither will List.<String>class.
If you're wondering "why", I'm writing an implementation of Spring's ...
Let's say I have the classes:
class Base{};
class A: public Base{
int i;
};
class B:public Base{
bool b;
};
And now I want to define a templated class:
template < typename T1, typename T2 >
class BasePair{
T1 first;
T2 second;
};
But I want to define it such that only decendants of class Base can be used as templa...
I'm coming from a c# background, how do generics look in java compared to c#? (basic usage)
...
I need to have the generic type parameter as an interface, however I would like to instantiate the type in the generic class (SomeGenericType) as follows:
class Program
{
static void Main(string[] args)
{
var val = new SomeGenericType<ISomeInterface>();
Console.ReadKey();
}
}
internal class SomeGenericType<...
Is there ever a difference between an unbounded wildcard e.g. <?> and a bounded wildcard whose bound is Object, e.g. <? extends Object>?
I recall reading somewhere that there was a difference in the early drafts of generics, but cannot find that source anymore.
...
In WPF app I use LINQ query to get values from ObservableCollection and update the state of some objects:
var shava = from clc in _ShAvaQuCollection where clc.xyID == "x02y02" select clc;
switch (shava.First().Status)
{
case 1:
x02y02.Status = MyCustControl.Status.First;
break...
Hi all,
First question here.
I am trying to instantiate a generic class using the type of a field.
public class ValueRange<type1>
{
type1 min;
type1 max;
}
void foo()
{
int k;
ValueRange<k.GetType()> range;
}
This doesn't work. Any suggestions?
Thanks in advance
...