English 中文(简体)
是否有办法推翻违约标的印刷
原标题:Is there a way to override the default object printing

我正试图用斜体印刷一个班子。 定义如下:

class Player(balance : Int, player_num :Int ){
    var curHand = new ArrayBuffer[Int]()
    var sum = 0

    def method1()={
        ....
    }
}

我想用以下几条文字印制:

var player1 = new Player(100,1)
println(player1)

是否有任何办法可以凌驾于你在ava中所能做的操作者之上,以达到这一目的,或者我不得不采取这样一种方法:

def print(){
    println("balance " + balance + "Player number" + player_num)
}

电话

var player1 = new Player(100,1)
player1.print()
问题回答
override def toString = "balance " + balance + " Player number " + player_num




相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签