- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Overriding a method that returns a repeated parameter
Fri, 2012-01-20, 19:31
Given a method that returns a repeated parameter (getXs below):
> scala> class A(xs: Int*) { def getXs = xs }
> defined class A
Is there any way to override that method? I've tried a whole pile of different constructs, none of which work:
> scala> class B extends A { override def getXs: Seq[Int] = Seq() }
> :8: error: overriding method getXs in class A of type => Int*;
> method getXs has incompatible type
> class B extends A { override def getXs: Seq[Int] = Seq() }
> ^
>
> scala> class B extends A { override def getXs: collection.mutable.WrappedArray[Int] = Array[Int]() }
> :8: error: overriding method getXs in class A of type => Int*;
> method getXs has incompatible type
> class B extends A { override def getXs: collection.mutable.WrappedArray[Int] = Array[Int]() }
> ^
>
> scala> class B extends A { override def getXs: Int* = Array[Int]() }
> :1: error: '=' expected but identifier found.
> class B extends A { override def getXs: Int* = Array[Int]() }
> ^
> :1: error: illegal start of simple expression
> class B extends A { override def getXs: Int* = Array[Int]() }
> ^
Is there any way to do this? I did find this related question on SO, but the answer was (to me, at least) unedifying:
http://stackoverflow.com/questions/5512402/overriding-a-repeated-class-p...
--
paul.butcher->msgCount++
Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?
http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: paul@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher
Fri, 2012-01-20, 20:11
#2
Re: Overriding a method that returns a repeated parameter
On 20 Jan 2012, at 18:39, Jason Zaugg wrote:
Great - thanks Jason!
--
paul.butcher->msgCount++
Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?
http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: paul@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher
See: https://issues.scala-lang.org/browse/SI-4176
Great - thanks Jason!
--
paul.butcher->msgCount++
Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?
http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: paul@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher
See: https://issues.scala-lang.org/browse/SI-4176
-jason