欢迎来到毕设资料网! | 帮助中心 毕设资料交流与分享平台
毕设资料网
全部分类
  • 毕业设计>
  • 毕业论文>
  • 外文翻译>
  • 课程设计>
  • 实习报告>
  • 相关资料>
  • ImageVerifierCode 换一换
    首页 毕设资料网 > 资源分类 > DOC文档下载
    分享到微信 分享到微博 分享到QQ空间

    计算机专业毕业设计外文翻译--面向Java开发人员的Scala指南类操作

    • 资源ID:130340       资源大小:115.50KB        全文页数:22页
    • 资源格式: DOC        下载积分:100金币
    快捷下载 游客一键下载
    账号登录下载
    三方登录下载: QQ登录
    下载资源需要100金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。

    计算机专业毕业设计外文翻译--面向Java开发人员的Scala指南类操作

    1、 - 1 - 来自: think in java ( 3) 外文原文 The busy Java developers guide to Scala: Class action It makes sense for Java developers to use objects as a first point of reference for understanding Scala. In this second installment of The busy Java developers guide to Scala series, Ted Neward follows a basic p

    2、remise of language measurement: that the power of a language can be measured in direct relation to its ability to integrate new facilities - in this case, support for complex numbers. Along the way youll see some interesting tidbits related to class definitions and usage in Scala. In last months art

    3、icle , you saw just a touch of Scalas syntax, the bare minimum necessary to run a Scala program and observe some of its simpler features. The Hello World and Timer examples from that article let you see Scalas Application class, its syntax for method definitions and anonymous functions, just a glimp

    4、se of an Array, and a bit on type-inferencing. Scala has a great deal more to offer, so this article investigates the intricacies of Scala coding. Scalas functional programming features are compelling, but theyre not the only reason Java developers should be interested in the language. In fact, Scal

    5、a blends functional concepts and object orientation. In order to let the Java-cum-Scala programmer feel more at home, it makes sense to look at Scalas object features and see how they map over to Java linguistically. Bear in mind that there isnt a direct mapping for some of these features, or in som

    6、e cases, the mapping is more of an analog than a direct parallel. But where the distinction is important, Ill point it out. Scala has class(es), too Rather than embark on a lengthy and abstract discussion of the class features that Scala supports, lets look at a definition for a class that might be

    7、used to bring rational number support to the Scala platform (largely swiped from Scala By Example - see Resources): Listing 1. rational.scala class Rational(n:Int, d:Int) private def gcd(x:Int, y:Int): Int = if (x=0) y else if (x0) gcd(-x, y) else if (y0) -gcd(x, -y) - 2 - else gcd(y%x, x) private v

    8、al g = gcd(n,d) val numer:Int = n/g val denom:Int = d/g def +(that:Rational) = new Rational(numer*that.denom + that.numer*denom, denom * that.denom) def -(that:Rational) = new Rational(numer * that.denom - that.numer * denom, denom * that.denom) def *(that:Rational) = new Rational(numer * that.numer

    9、, denom * that.denom) def /(that:Rational) = new Rational(numer * that.denom, denom * that.numer) override def toString() = Rational: + numer + / + denom + While the overall structure of Listing 1 is lexically similar to what youve seen in Java code over the last decade, some new elements clearly ar

    10、e at work here. Before picking this definition apart, take a look at the code to exercise the new Rational class: Listing 2. RunRational class Rational(n:Int, d:Int) / . as before object RunRational extends Application val r1 = new Rational(1, 3) val r2 = new Rational(2, 5) val r3 = r1 - r2 val r4 =

    11、 r1 + r2 Console.println(r1 = + r1) Console.println(r2 = + r2) Console.println(r3 = r1 - r2 = + r3) - 3 - Console.println(r4 = r1 + r2 = + r4) What you see in Listing 2 isnt terribly exciting: I create a couple of rational numbers, create two more Rationals as the addition and subtraction of the fir

    12、st two, and echo everything to the console. (Note that Console.println() comes from the Scala core library, living in scala.*, and is implicitly imported into every Scala program, just as java.lang is in Java programming.) How many ways shall I construct thee? Now look again at the first line in the

    13、 Rational class definition: Listing 3. Scalas default constructor class Rational(n:Int, d:Int) / . Although you might think youre looking at some kind of generics-like syntax in Listing 3, its actually the default and preferred constructor for the Rational class: n and d are simply the parameters to

    14、 that constructor. Scalas preference for a single constructor makes a certain kind of sense - most classes end up having a single constructor or a collection of constructors that all chain through a single constructor as a convenience. If you wanted to, you could define more constructors on a Ration

    15、al like so: Listing 4. A chain of constructors class Rational(n:Int, d:Int) def this(d:Int) = this(0, d) Note that Scalas constructor chain does the usual Java-constructor-chaining thing by calling into the preferred constructor (the Int,Int version). Details, (implementation) details. When working

    16、with rational numbers, it helps to perform a bit of numerical legerdemain: namely that of finding a common denominator to make certain operations easier. If you want to add 1-over-2 (also known as one-half) to 2-over-4 (also known as two-fourths), the Rational class should be smart enough to realize that 2-over-4 is the same as 1-over-2, and convert it accordingly before adding the two together.


    注意事项

    本文(计算机专业毕业设计外文翻译--面向Java开发人员的Scala指南类操作)为本站会员(泛舟)主动上传,毕设资料网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请联系网站客服QQ:540560583,我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们
    本站所有资料均属于原创者所有,仅提供参考和学习交流之用,请勿用做其他用途,转载必究!如有侵犯您的权利请联系本站,一经查实我们会立即删除相关内容!
    copyright@ 2008-2025 毕设资料网所有
    联系QQ:540560583