freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

計(jì)算機(jī)專業(yè)畢業(yè)設(shè)計(jì)外文翻譯--面向java開發(fā)人員的scala指南類操作-文庫(kù)吧在線文庫(kù)

  

【正文】 r1) (r2 = + r2) (r3 = r1 r2 = + r3) (r4 = r1 + r2 = + r4) } 清單 2 中的內(nèi)容平淡無奇:先創(chuàng)建兩個(gè)有理數(shù),然后再創(chuàng)建兩個(gè) Rational,作為前面兩個(gè)有理數(shù)的和與差,最后將這幾個(gè)數(shù)回傳到控制臺(tái)上(注意, ()來自Scala核心庫(kù),位于 scala.* 中,它被隱式地導(dǎo)入每個(gè) Scala 程序中,就像 Java編程中的)。 回顧一下 清單 1就會(huì)發(fā)現(xiàn),我創(chuàng)建了一個(gè)覆蓋的 toString方法來返回 Rational 的值,在 RunRational 驅(qū)動(dòng)程序代碼中使用 toString時(shí),這樣做非常有用。 Rational 類仍 然有 3個(gè)私有字段: n、 d和 g,但是,其中的 n和 d被默認(rèn)定義為私有訪問,而 g則被顯式地定義為私有訪問,它們對(duì)于外部都是隱藏的。 操作符 記住,在 Scala中 一切都是對(duì)象 。 但是請(qǐng)注意,這些操作符每次操作時(shí)都構(gòu)造一個(gè)新的 Rational 對(duì)象。 這條規(guī)則與 “一切都是對(duì)象 ” 規(guī)則結(jié)合起來,可以實(shí)現(xiàn)功能強(qiáng)大(但很簡(jiǎn)單)的代碼: 清單 7. 求和 1 + 2 + 3 // same as 1.+(2.+(3)) r1 + r2 + r3 // same as r1.+(r2.+(r3)) 當(dāng)然,對(duì)于簡(jiǎn)單的整數(shù)加法, Scala 編譯器也會(huì) “得到正確的結(jié)果 ”,它們?cè)谡Z(yǔ)法上是完全一樣的。 private int g。 public int denom()。您可能會(huì)注意到,大寫的 Int類型與 有點(diǎn)相似, Scala編譯器非常聰明,會(huì)在類定義中將它們轉(zhuǎn)換成常規(guī)的 Java原語(yǔ) int。 assertTrue(() == 1)。 } // ... some details omitted } 除了確認(rèn) Rational 類運(yùn)行正常之外,上面的測(cè)試套件還證明可以從 Java代碼中調(diào)用 Scala代碼(盡管在操作符方面有點(diǎn)不匹配)。在某些方面,如今的 Java開發(fā)人員也可以將 Scala看作是“更好的 Java”,因?yàn)樗峁┝艘环N編寫傳統(tǒng) Java POJO的更簡(jiǎn)潔的方式。 } public int getAge() { return 。而且,如果目標(biāo)是減少 Person中的代碼行數(shù),那么可以刪除整個(gè) getFoo屬性方法,因?yàn)?Scala將為每個(gè)構(gòu)造函數(shù)參數(shù)生成 accessor 方法 —— firstName()返回一個(gè) String,lastName()返回 一個(gè) String, age()返回一個(gè) int。 private String lastName。 } public String getFirstName() { return 。 為了調(diào)用那些方法,需要用 Groovy或 JRuby(或者其他對(duì) $字符沒有限制的語(yǔ)言)編寫測(cè)試,或者編寫 Reflection代碼來調(diào)用它。 Rational r3 = (Rational) reflectInvoke(r1, $plus, r2)。 assertTrue(() == 2)。 public Rational(int)。 public Rational $div(Rational)。 Scala 內(nèi)幕 記住, Scala將被編譯為 Java字節(jié)碼,這意味著它在 JVM上運(yùn)行。 第二個(gè)影響是, Scala語(yǔ)言設(shè)計(jì)者提供的操作符與 Scala程序員認(rèn)為 應(yīng)該 提供的操作符之間沒有特別的差異。只不過它們的名稱比較古怪罷了。因此,至少對(duì)于這個(gè)例子而言,我將保持 Rational 不變。相反,函數(shù)中的最后一個(gè)值將被隱式地當(dāng)作返回值(但是,如果您更喜歡 Java語(yǔ)法,也可以使用 return關(guān)鍵字)。 實(shí)現(xiàn)細(xì)節(jié) 在處理有理數(shù)時(shí),采取一點(diǎn)數(shù)值技巧將會(huì)有所幫助:也就是說,找到公分母,使某些操作變得更容易。為了讓 Java和 Scala程序員感到得心應(yīng)手,可以了解一下 Scala 的對(duì)象特性,看看 它們是如何在語(yǔ)言方面與 Java對(duì)應(yīng)的。s article will mark the beginning of our descent into the deep end of the functional pool. 13 外文翻譯 面向 Java開發(fā)人員的 Scala指南 :類操作 Java? 開發(fā)人員可以將對(duì)象作為理解 Scala的出發(fā)點(diǎn)。 private String lastName。 } public String getFirstName() { return 。 } // ... some details omitted } Aside from confirming that the Rational class behaves, well, rationally, the above test suite also proves that it is possible to call Scala code from Java code (albeit with a little bit of an impedance mismatch when it es to the operators). The cool thing about this, of course, is 9 that it lets you try out Scala slowly, by migrating Java classes over to Scala classes without ever having to change the tests that back them. The only weirdness you might notice in the test code has to do with operator invocation, in this case, the + method on the Rational class. Looking back at the javap output, Scala has obviously translated the + function into the JVM method $plus, but the Java Language Specification does not allow the $ character in identifiers (which is why it39。 assertTrue(() == 1)。 } C:\Projects\scalaclasses\code The operators defined in the Scala class transmogrify into method calls in the best tradition of Java programming, though they do seem to be based on funny names. Two constructors are defined on the class: one taking an int and one taking a pair of ints. And, if you happen to be at all concerned that the use of the uppercase Int type is somehow a in disguise, note that the Scala piler is smart enough to transform them into regular Java primitive ints in the class definition. Testing, testing, 123... It is a wellknown meme that good programmers write code, and great programmers write tests。 public Rational $minus(Rational)。t have an explicit definition for +=: Listing 8. Scala infers var r5 = new Rational(3,4) r5 += r1 (r5) When printed, r5 has the value [13 / 12], which is exactly what it should be. Scala under the hood Remember that Scala piles to Java bytecode, meaning that it runs on the JVM. If you need proof, look no further than the fact that the piler is producing .class files that begin with 0xCAFEBABE, just like javac does. Also note what happens if you fire up the Java bytecode disassembler that es with the JDK (javap) and point it at the generated Rational 7 class, as shown in Listing 9: Listing 9. Classes piled from C:\Projects\scalaclasses\codejavap private classpath classes Rational Compiled from public class Rational extends implements { private int denom。 that is to say, in this particular case, there is no distinction between a function named add and a function named +. In Scala, all operators are functions on a class. They just happen to have, well, funky names. In the Rational class, then, four operations have been defined for rational numbers. These are the canonical, mathematical operations add, subtract, multiply, and divide. Each of these is named by its mathematical symbol: +, , *, and /. Notice, however, that each of these operators works by constructing a new Rational object each time. Again, this is very similar to how works, and it is the default implementation because it yields threadsafe code. (If no shared state and internal state of an object shared across threads is implicitly shared state is modified by a thread, then there is no concern over concurrent access to that state.) What39。s constructor chain does the usual Javaconstructorchaining thing by calling into the preferred constructor (the Int,Int version). Details, (implementation) details... When working with rational numbers, it helps to perform a bit of numerical legerdemain: namely that of finding a mon denominator to make certain operations easier. If you want to add 1over2 (also known as onehalf) to 2over4 (also known as twofourths), the Rational clas
點(diǎn)擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計(jì)相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1