new operator - How do I create an instance of a trait in a generic method in scala? -


I am trying to create an example of a property using this method

  New object with val inst mitrate  

It works well, but I want to take this creation to the generator function, ie.

  Object creator {Def [T]: T = with new object t}  

I need to appear clearly that in some way Fix the trash problems, but before I get into it, I have 2 questions:

  1. Even with an inherent manifest, Scala is still Demands that T is a specialty. How do I add a restriction to make T [T], so that T is a feature?

  2. If I decide to use the class. Instead of using the application method to create a dynamic example of "new", I "new object with T How do I specify "with" in "? Is the new concrete mix type dynamically possible on runtime?

You can not do this (even if one clearly) code T With a new object created in the new object in which is an combination with object T. To pass it on your build function, you have to generate this new class (with the new bytecode) on the runtime, and there is no facility to create a new square at runtime in Scala.

Instead of a strategy, you have to try to shift the special functionality of the factory method to the creator of the class, and then you can use the constructor directly.

Another possible strategy is to create conversion functions (implicit or otherwise) that are the qualities you are interested in using with this class.


Comments