• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Half baked ideas

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #11
    Lots of contracts porting Java to C#.

    I wonder why?

    Comment


      #12
      OK

      I have an interface Wotsit<T> { T doStuff(); }

      I want a factory method that returns a Wotsit for different types of T. It needs to support multiple types, lookup a wotsit based on the return type, and support runtime registration of new types and associated wotsits, so the factory method needs to take the return type as a parameter. I can do this as long as T isn't a generic type. Unfortunately I need it to support generic types.

      e.g. I can do this
      Wotsit<Blah> myWotsit = WotsitFactory.getWotsit(Blah.class);
      Blah result = myWotsit.doStuff();

      but this doesn't work

      Wotsit<List<Blah>> myWotsit = WotsitFactory.getWotsit(List<Blah>.class);
      List<Blah> result = myWotsit.doStuff();
      for (Blah blah : result) {
      ....

      Yes, I know I can use Object, but I don't want to, that defeats the point of using generics in the first place. I might as well be using ******* void *

      Can C# do this?

      What I can do is create a non generic class that implements List<Blah> and then use something like

      Wotsit<? extends List<Blah>> myWotsit = WotsitFactory.getWotsit(BlahList.class);

      What a PITA.

      Especially when you have List<BlahList> to deal with. One BlahListListListListList coming up.
      Last edited by doodab; 15 July 2013, 21:50.
      While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

      Comment


        #13

        Comment


          #14
          Originally posted by mudskipper View Post
          Is this why I see so many oompa loompas walking the streets?
          While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

          Comment

          Working...
          X