scala 기초 16 - trait 초기 탐색/대상 에 trait 섞 기

928 단어 Scala
/*
 * trait  java interface,  interface  
 *  java  ,trait          
 *          ,       trait      override   (     ,   override)
 */

trait Cloneable extends java.lang.Cloneable

trait Logger {
//  def log(msg: String)
  def log(msg: String) {}
}

/*
 *   trait  extends
 *       trait,extends   with
 */
class ConcreateLogger extends Logger with Cloneable {
//  def log(msg: String) = println ("Log: " + msg)
  
  def concreteLog {
    log("It is me")
  }
}

/*
 *    Logger,  log  
 */
trait TraitLogger extends Logger {
  override def log(msg: String) {
    println("TraitLogger log content is: " + msg)
  }
}

object Test {
  def main(args: Array[String]) {
    /*
     *             
     * trait           ,            
     *   :TraitLogger     ConcreateLogger     Logger,        
     */
    val logger = new ConcreateLogger with TraitLogger
    logger.concreteLog
  }
}

좋은 웹페이지 즐겨찾기