Re: Scala: Overload method by its class type

2015-08-29 Thread Akhil Das
This is more of a scala related question, have a look at the case classes
in scala http://www.scala-lang.org/old/node/107

Thanks
Best Regards

On Tue, Aug 25, 2015 at 6:55 PM, saif.a.ell...@wellsfargo.com wrote:

 Hi all,

 I have SomeClass[TYPE] { def some_method(args: fixed_type_args): TYPE }

 And on runtime, I create instances of this class with different AnyVal +
 String types, but the return type of some_method varies.

 I know I could do this with an implicit object, IF some_method received a
 type, but in this case, I need to have the TYPE defined on its class
 instance, so for example:

 val int_instance = new SomeClass[Int]
 val str_instance = new SomeClass[String]
 val result: Boolean = int_instance.some_method(args)  0   --- I
 expected INT here
 val result2: Boolean = str_instance.som_method(args) contains “asdfg”
  I expected STRING here.

 without compilation errors.

 Any ideas? I would like to implement something like this:

 class SomeClass[TYPE] {

 def some_method(args: Int): Int = {
 process_integer_overloaded_method
 }

 def some_method(args: Int): String = {
 process_string_overloaded_method
 }

 and so on.

 Any ideas? maybe store classe’s TYPE in a constructor instead as a
 variable somehow?

 Thanks
 Saif




Scala: Overload method by its class type

2015-08-25 Thread Saif.A.Ellafi
Hi all,

I have SomeClass[TYPE] { def some_method(args: fixed_type_args): TYPE }

And on runtime, I create instances of this class with different AnyVal + String 
types, but the return type of some_method varies.

I know I could do this with an implicit object, IF some_method received a type, 
but in this case, I need to have the TYPE defined on its class instance, so for 
example:

val int_instance = new SomeClass[Int]
val str_instance = new SomeClass[String]
val result: Boolean = int_instance.some_method(args)  0   --- I expected 
INT here
val result2: Boolean = str_instance.som_method(args) contains asdfg  
I expected STRING here.

without compilation errors.

Any ideas? I would like to implement something like this:

class SomeClass[TYPE] {

def some_method(args: Int): Int = {
process_integer_overloaded_method
}

def some_method(args: Int): String = {
process_string_overloaded_method
}

and so on.

Any ideas? maybe store classe's TYPE in a constructor instead as a variable 
somehow?

Thanks
Saif