• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala typeOf类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中scala.reflect.runtime.universe.typeOf的典型用法代码示例。如果您正苦于以下问题:Scala typeOf类的具体用法?Scala typeOf怎么用?Scala typeOf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了typeOf类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: ShapelessTest

//设置package包名称以及导入依赖的类
package com.nekopiano.scala.scalasandbox.types


object ShapelessTest {

  def main(args: Array[String]): Unit = {
    var hm = new HMap
    hm.set("hoge", 1)
    hm.set("fuga", "moge")
    hm.get[Int]("hoge")
    hm.get[String]("fuga")
    hm.get[String]("hoge")

    println(hm)
  }
  class HMap {
    import scala.reflect.runtime.universe.{ typeOf, TypeTag, Type }
    private var m = Map[String, (Type, _)]()
    def set[T: TypeTag](k: String, v: T): Unit = { m += k -> (typeOf[T] -> v) }
    def get[T: TypeTag](k: String): Option[T] = m.get(k) flatMap {
      case (t, v) if t <:< typeOf[T] => Some(v.asInstanceOf[T])
      case _ => None
    }
  }
} 
开发者ID:lamusique,项目名称:ScalaSandbox,代码行数:26,代码来源:ShapelessTest.scala


示例2: InjectRuntimeGeneratorsTest

//设置package包名称以及导入依赖的类
package org.dama.datasynth.runtime.spark.passes

import org.dama.datasynth.executionplan.ExecutionPlan
import org.dama.datasynth.executionplan.ExecutionPlan.PropertyTable
import org.scalatest.{FlatSpec, Matchers}
import scala.reflect.runtime.universe.{TypeTag, typeOf}


class InjectRuntimeGeneratorsTest extends FlatSpec with Matchers {

  "The source code for a boolean runtime property generator with a dependency " should " be correctly generated " in {

    val size = ExecutionPlan.StaticValue[Long](1000)
    val valueFloat = ExecutionPlan.StaticValue[Float](1.0f)
    val generatorFloat = ExecutionPlan.PropertyGenerator[Float]("org.dama.datasynth.common.generators.property.dummy.DummyFloatPropertyGenerator",Seq(valueFloat),Seq())
    val tableFloat = PropertyTable[Float]("float","property",generatorFloat,size)

    val valueBoolean = ExecutionPlan.StaticValue[Boolean](true)
    val generatorBoolean = ExecutionPlan.PropertyGenerator[Boolean]("org.dama.datasynth.common.generators.property.dummy.DummyBooleanPropertyGenerator",Seq(valueBoolean),Seq(tableFloat))
    val tableBoolean = PropertyTable[Boolean]("boolean","property",generatorBoolean,size)

    val generatorMap : Map[String,String] = Map( "boolean.property" -> "BOOLEANPROPERTY", "float.property" -> "FLOATPROPERTY")
    val injectRuntimeGenerators = new InjectRuntimeGenerators(generatorMap)
    val executionPlan = injectRuntimeGenerators.run(Seq(tableBoolean,tableFloat))
    executionPlan(0) match {
      case table : PropertyTable[[email protected]] if table.tag.tpe =:= typeOf[Boolean] => table.generator.className should be ("BOOLEANPROPERTY")
      case _ => throw new RuntimeException("Table is not of type PropertyTable[Boolean]")
    }

    executionPlan(1) match {
      case table : PropertyTable[[email protected]] if table.tag.tpe =:= typeOf[Float] => table.generator.className should be ("FLOATPROPERTY")
      case _ => throw new RuntimeException("Table is not of type PropertyTable[Float]")
    }
  }
} 
开发者ID:DAMA-UPC,项目名称:DataSynth,代码行数:36,代码来源:InjectRuntimeGeneratorsTest.scala


示例3: UnitConverterPresenter

//设置package包名称以及导入依赖的类
package com.stulsoft.pscalafx.demo1

import scala.reflect.runtime.universe.typeOf
import scalafx.application.{Platform, JFXApp}
import scalafx.Includes._
import scalafx.scene.Scene
import scalafx.scene.control.{ComboBox, TextField}
import scalafx.event.ActionEvent
import scalafxml.core.{DependenciesByType, FXMLView}
import scalafxml.core.macros.sfxml
import javafx.beans.binding.StringBinding


@sfxml
class UnitConverterPresenter(from: TextField,
                             to: TextField,
                             types: ComboBox[UnitConverter],
                             converters: UnitConverters) {

  // Filling the combo box
  for (converter <- converters.available) {
    types += converter
  }
  types.getSelectionModel.selectFirst()

  // Data binding
  to.text <== new StringBinding {
    bind(from.text.delegate, types.getSelectionModel.selectedItemProperty)

    def computeValue(): String = types.getSelectionModel.getSelectedItem.run(from.text.value)
  }

  // Close button event handler
  def onClose(event: ActionEvent) {
    Platform.exit()
  }
}

object ScalaFXML extends JFXApp {

  val root = FXMLView(getClass.getResource("/fxml/unitconverter.fxml"),
    new DependenciesByType(Map(
      typeOf[UnitConverters] -> new UnitConverters(InchesToMM, MMtoInches))))

  stage = new JFXApp.PrimaryStage() {
    title = "Unit conversion"
    scene = new Scene(root)

  }
} 
开发者ID:ysden123,项目名称:poc,代码行数:51,代码来源:ScalaFXML.scala


示例4: MainViewController

//设置package包名称以及导入依赖的类
package de.m7w3.signal.controller

import de.m7w3.signal.ApplicationContext
import scala.reflect.runtime.universe.{Type, typeOf}

import scalafx.Includes._
import scalafx.scene.Parent
import scalafxml.core.{DependenciesByType, FXMLView}
import scalafxml.core.macros.{nested, sfxml}

@sfxml
class MainViewController(@nested[EditMenuController] editMenuController: MenuController,
                          @nested[FileMenuController] fileMenuController: MenuController,
                          @nested[HelpMenuController] helpMenuController: MenuController,
                          applicationContext: ApplicationContext) {

}

object MainView {
  def load(context: ApplicationContext): Parent = {
    val dependencies = Map[Type, Any](
      typeOf[ApplicationContext] -> context
    )
    val resourceUri = "/de/m7w3/signal/main_view.fxml"
    val fxmlUri = getClass.getResource(resourceUri)
    require(fxmlUri != null, s"$resourceUri not found")
    FXMLView(fxmlUri, new DependenciesByType(dependencies))
  }
} 
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:30,代码来源:MainViewController.scala



注:本文中的scala.reflect.runtime.universe.typeOf类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala SLF4JBridgeHandler类代码示例发布时间:2022-05-23
下一篇:
Scala Charsets类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap