Scala's interoperability with Java

Source: Internet
Author: User


Java is used in conjunction with Scala:

The list of Java and the conversion of the Scala buffer:

The premise is that the converted Java type and Scala type must also be import, then import Scala.collection.javaconversions._, and the set of conversions must have a definite type

?

Import Scala.collection.javaConversions.bufferAsJavaList

Val javalist = new Processbuilder (ArrayBuffer (1))//It will return a Javalist object

Import Scala.collection.mutable.ArrayBuffer

Val Buff:buffer[int] = new Java.util.arraylist[int] ()//It will automatically turn into Buffer

Import Scala.collection.javaConversions.mapAsScalaMap

Val scalamap = new Java.util.treemap[string,int]//It will automatically turn into a map in Scala

Import Scala.collection.JavaConversions.propertiesAsScalaMap

Val scalamap = system.getproperties ()//It will automatically turn into a map in Scala

Import Scala.collection.javaConversions.mapAsJavaMap

Import Java.awt.font.textattribute._//Introduce the key that will be used in the map below

Val Font = new Java.awt.Font (Map ("1" and 1, "2", 2))//The method expects a Java mapping


Scala's interoperability with Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.