scala - Can't access generic function type in a inner PartialFunction -


I am currently writing a generic function to execute dispatch async requests, but in dispatch handlers I can not access the normal type:

  execution of personal def [message type] (query: rick, error message: string) {html (ok as query string. Either.Success {case left (error) = & gt; Println (errorMsg) case correct (JSN) = & gt; println (new message per second (json)) // error here}}   

I have an error on the new messaging: "New Message Type (JSN)" in "did not resolve the icon message type Can you help me?

Thanks in advance

Victor

EDIT: I have found another interesting method here. You must use the Manifest feature:

  class DynamicTestClass () {def output () {println ("Hello from class dynamically sent")}} def testFunc [T: Manifest] (): T = {manifest {T] .erasure.newInstance (). AsInstanceOf [T] val dynamicTestClassInstance = testFunc [DynamicTestClass] () dynamicTestClassInstance.output ()   

It starts working!

You can not do this

  def must MakeA [A] (B: string): A = new A (B)   

in Scala.

For some practical reasons Scalak should know that if A is the public constructor and its logic?

However, you can use a smart design, for example, how to create a type class that knows "know" parameters:

  class message (Val Value: string) attribute maker [A] {def cons (b: String)} contained class messagecaught (M: message) constructor [message] {def cons (b: string) = new message (b)}  < / pre> 

Now voilÃ, we now rewrite our mustMakeA :

  def should make [a: constructor] (b : String): A = Inspector [Constructor [A]] cons (b) Mekey [Message] ("Example") // Let us get a new message ("Example") `  

BTW, I have not tested the code, so there may be some tweaking in it.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -