ClassOf

获取类信息

package chapter01

object test17 {
  def main(args:Array[String]):Unit={

  //scala获取类信息:classOf[]
    //classOf能直接使用,因为scala.Predef伴生对象默认导入到当前环境中
    var userClass :Class[User27] = classOf[User27]
    userClass.getInterfaces


    //type给类起别名
    type user = User27

    var user:Object=new User27()
    //判断class类型:isInstanceOf
    var bool:Boolean= user.isInstanceOf[User27]
    if(bool){
      
      //转化class类型:asInstanceOf
      var user1:User27=bool.asInstanceOf[User27]
    }

  }
}

class User27{}

 

posted on 2020-08-09 16:48  happygril3  阅读(287)  评论(0)    收藏  举报

导航