scala> def foo[U](t: Any) = t.asInstanceOf[U]
foo: [U](t: Any)U
scala> val s: String = foo("hi")
scala> val n = foo("hi")
java.lang.ClassCastException: java.lang.String cannot be cast to scala.runtime.Nothing$
    at .<init>(<console>:6)
    at .<clinit>(<console>)
    at RequestResult$.<init>(<console>:9)
    at RequestResult$.<clinit...
            
           
          
            
            This simple class 
public class Test<T>
{
    public static void A(Window wa, Window wb)
    {
        wa.Closed += (s, e) => wb.Close();
    }
}
Gets compiled to this (I'm using Reflector to decompile) :
public class Test<T>
{
    [CompilerGenerated]
    private sealed class <>c__DisplayClass1
    {
        public Window wb;
      ...
            
           
          
            
            Say I have this interface:
public interface IRepository<T> where T : Entity
{
  T Get(string query);
  void Save(T entity);
}
And I have a couple of concrete classes like (where User and Project, of course, inherit from Entity):
public class UserRepository : IRepository<User> { ... }
public class ProjectRepository : IProjectRepositor...
            
           
          
            
            I have instantiated an object like this:
GraphMatrixDirected<String, Integer> g
g is passed to a function like this:
floyd(g);
floyd's signature looks like this:
public void floyd(GraphMatrixDirected<V,E> g) 
Eclipse gives me an error saying: 
The method floyd(GraphMatrixDirected<V,E>) in the type GraphMatrix<V,E> is not applic...
            
           
          
            
            How to I reflect back the name of a type that is supplied as a generic parameter?  I would really like to know how this is done in both C# and VB.NET.  See the following example code and expected response.  
In C#:
public void Test<T>()
{
     Console.WriteLine("The supplied type is {0}",???)
}
In VB.NET
Public Sub Test(Of T)()
    ...
            
           
          
            
            I have a litte problem and was wondering how to solve it. I have a generic class Tuple<A,B> and now I would like to sort their tuples according to A and B. It should look like this:
Unsorted:
(1,5)
(2,8)
(6,8)
(1,4)
(2,4)
Sorted:
(1,4)
(1,5)
(2,4)
(2,8)
(6,8)
For that reason I thought of implementing a generic compare method (pu...
            
           
          
            
            So, I have an abstract class like:
public abstract class AbstractParent <E extends Enum<E>> {...}
Somewhere in a non-abstract method inside AbstractParent, I would like to iterate over the values of E. Is this possible?
For a better example:
public abstract class AbstractParent <E extends Enum<E>> {
    ...
    protected void doSome...
            
           
          
            
            Hi,
I have a generic method that has some parameter of a generic Type. What I want to do, is be able to access the method on this generic type parameter inside my function.
    public void dispatchEvent<T>(T handler, EventArgs evt)
        {
            T temp = handler; // make a copy to be more thread-safe
            if (temp != nul...
            
           
          
            
            I think I must be missing something, why can't I compile this:
class Foo<T> where T : Bar
{
    T Bar;
}
abstract class Bar
{ }
class MyBar : Bar
{ }
static void Main(string[] args)
{
    var fooMyBar = new Foo<MyBar>();
    AddMoreFoos(fooMyBar);
}
static void AddMoreFoos<T>(Foo<T> FooToAdd) where T : Bar
{
    var listOfFoos = new...
            
           
          
            
            I'm writing a bijective dictionary class, but I want to ensure the two generic types are not the same type for two reasons.
Firstly, I would like it to implement the IDictionary interface in both directions, but 
public class BijectiveDictionary<TKey, TValue>
    : IDictionary<TKey, TValue>, IDictionary<TValue, TKey>
gives me " 'Bije...
            
           
          
            
            I have a List with a few strings in it. I want to see if it contains a a string that starts with 'blah' however, I'm not sure how to use the (this IEnumerable source, value):bool overload of List.Contains.
...
            
           
          
            
            Hi,
In my current project I'm currently trying to replace the Windsor IoC in favour of structure map (2.6.1). But having a bit of problem registering some generic types. How would I register IFilterConverter<T> to use FilterConverter<SomeSpecificType>. I've tried ConnectImplementationsToTypesClosing(IFilterConverter) but from what I've ...
            
           
          
            
            Sorry for asking what seems like such an obvious question.
I have an "adapter" generic class of type T where T is a defined interface. I want to create a method in that class which takes a different type of generic adapter.
public interface ICommon { }
public class TypeOne : ICommon { }
public class TypeTwo : ICommon { }
public class ...
            
           
          
            
            I have a delegate 
delegate string Mathop<T,F>(T a,F b); 
and I am declaring an event like
event Mathop<T,F> someevent;
But here I am getting an error. It says 'T' could not be found. I want my Mathop delegate to work as an eventhandler for my event.
What I am doing wrong here.
...
            
           
          
            
            To create a List, why doesn't Java allow them to be created then elements added one by one?
This works:
public static List<TrackedItem> create(List<Item> items)
{
    TrackedItem[] arr = new TrackedItem[items.size()];
    int i = 0;
    for (Item item : items)
    {
        arr[i] = TrackedItem.createOrUpdate(item);
        i++;
    ...
            
           
          
            
            I have the following C# helper class which retrieves a Json String from a remote server and casts it to the type I need.
public class JsonHelper
{
    private JavaScriptSerializer serializer = new JavaScriptSerializer();
    public T GetValue<T>(string methodName, object param) where T : IConvertible
    {
        string result = GetJs...
            
           
          
            
            Hello.
I'm having a little trouble with some casts that i cant figure out out to solve.
I have this interface and the following implementations:
public interface IConfigureServiceOnServer
{
    void Configure(Service service);
}
public sealed class ServiceConfigurator : IConfigureServiceOnServer
{
 ...
}
I'm loading these types at ...
            
           
          
            
            The class Object contains the following method:
public final Class<? extends Object> getClass().
why the return type of this method is Class<? extends Object>
...
            
           
          
            
            hi,
my IDE generates a warning when i use the following code:
aMethod(List.class);
"Type safety: The expression of type List needs unchecked conversion to conform to ..."
Sadly when i try to let the IDE fix it, it doesn't work. What is the proper syntax to infere the generic type ? Thx in advance for any help.
edit: 
Signature of t...
            
           
          
            
            The my question is this:
Why can not instantiate a generic type with new T () and instead with newInstance() of the class Class you can do?
...