
scala
文章平均质量分 61
DViewer
求知者
展开
-
scala for表达式
1. for如果愿意的话,你可以使用大括号代替小括号环绕发生器和过滤器。使用大括号的一个好处是你可以省略一些使用小括号必须加的分号。转载 2014-10-26 21:57:39 · 1094 阅读 · 0 评论 -
scala里的静态代理(static-forwarders)
静态代理(static-forwarders)是编译器针对从java调用scala的object里的方法提供的一种便捷。比如,我们如何在java中调用下面object里的foo方法?$ cat A.scala object A { def foo() = 2}按照通常的逻辑,我们需要在java里获取到这个单例对象,然后通过这个对象调用foo方法,不过这样做的前提你需要转载 2015-11-28 18:03:32 · 572 阅读 · 0 评论 -
Scala-maven-plugin and Multiple Versions of Scala Libraries Detected
Have you ever seen messages like these running scala-maven-plugin?1234[WARNING] Expected all dependencies to require Scala version: 2.10.3[WARNING] mycoolcompany:mycoolproject转载 2015-12-18 18:31:06 · 3698 阅读 · 0 评论 -
Loan Pattern
In OO programming, classes (or objects) abstract and encapsulate behavior and data. Function values also abstract and encapsulate behavior. And rather than holding on to state, they can help transform转载 2016-01-05 11:21:10 · 620 阅读 · 0 评论 -
A simple Scala call-by-name example
Here's a simple Scala call-by-name example. I'll show the normal approach to writing a method and passing in a parameter, and then show a call-by-name (pass by name) example.1) A "normal" Scala method转载 2016-01-05 16:34:54 · 587 阅读 · 0 评论 -
Scala and Evaluation Strategy
Once you use any technology to a significant extent, you understand its strength and shortcomings. I've probably written tens of thousands of lines of code in Delphi or C++, Java and C# too to some ex转载 2016-01-05 16:36:22 · 487 阅读 · 0 评论 -
Scala map() vs map{}
I was wondering the other day what the difference really was, in Scala, between1 val list = List(1, 2, 3, 4)2 list.map(x => x * x)and1 val list = List(1, 2, 3, 4)2 list.map { x => x *转载 2016-04-04 00:32:12 · 708 阅读 · 0 评论 -
Scala - Parentheses and Curly Brackets in Anonymous Functions
Scala gives a lot of flexibility in defining anonymous functions, and that might lead to a confussion. Jacek Laskowski asked an interesting question on stackoverflow.comregarding of calling a map转载 2016-04-04 01:40:12 · 712 阅读 · 0 评论 -
scala抽象类型
(通过一个例子来说明抽象类型的用法,假定你需要为动物的饮食习性建模, 你可能会定义如下的数据结构:class Foodabstract class Animal { def eat(food: Food)}然后呢可能需要实现两个不同的实类对于与牛和草 Cows和Grassclass Grass extends Foodclass Cow extends Animal {转载 2016-02-27 16:04:40 · 523 阅读 · 0 评论 -
A Deeper Look at the Scala Syntax (scala block)
Scala is an object-oriented, statically-typed and functional programming language for the JVM. The strength of Scala lies in it’s powerful syntax which allows to write readable, manageable code w转载 2016-03-27 03:23:14 · 591 阅读 · 0 评论 -
The Option Type
The basic ideaIf you have worked with Java at all in the past, it is very likely that you have come across a NullPointerException at some time (other languages will throw similarly named errors转载 2016-10-19 17:46:23 · 898 阅读 · 0 评论 -
TypeSafe config & HOCON + Read properties in java (with example)
Given a java application, We would like to read the property file defined in HOCON (Human-Optimized Config Object Notation.) format.The property files use the suffix .conf e.g. application.conf, ref转载 2016-11-15 14:41:07 · 1913 阅读 · 0 评论 -
scala:函数即对象
在Scala里,我们经常讨论对象-函数编程。它表示什么呢?函数究竟是什么?函数是一系列的trait。确切地说,有一个参数的函数是Function1 trait的一个实例。这个trait定义了我们之前学到的apply()的语法糖,它允许你像调用函数一样调用对象。1234567scala> object addOneexten转载 2015-11-28 18:01:54 · 1180 阅读 · 0 评论 -
maven for scala
Introduction to mavenMaven is a builder like make or ant, written in java. It's a commande line tool, IDE (Eclipse, Netbeans, IDEA) have plugins to handle and integrate project powered by转载 2015-08-09 17:48:13 · 595 阅读 · 0 评论 -
What does => and () => mean in Scala
=> is syntactic sugar for creating instances of functions. Recall that every function in scala is an instance of a class.For example, the type Int => String, is equivalent to the type Function转载 2015-08-01 21:17:08 · 452 阅读 · 0 评论 -
Map, Map and flatMap in Scala
One of the things I like about Scala is it’s collections framework. As a non CS graduate I only very lightly covered functional programming at university and I’d never come across it until Scala. One转载 2015-08-15 16:21:01 · 753 阅读 · 0 评论 -
Recursive Type Signatures in Scala
Have you seen a type signature like this before?1trait T[U T[U]]If you’re like me, you’ve come across this type signature, and you’re wondering what the heck it me转载 2015-12-28 15:29:49 · 564 阅读 · 0 评论 -
Scala: Linearization technique to avoid multiple inheritance
To support inheritance Scala has introduced a concept called trait almost similar to Java`s interface. But unlike Java interfaces, Scala traits can actually define any concrete methods. From this it s转载 2015-12-28 15:37:29 · 674 阅读 · 0 评论 -
Class Linearization in Scala
Scala has a wealth of language constructs that support modern object-oriented programming. Class Linearization stands in the heart of its object model. Section 12.6 in Artima's Programming Scala is转载 2015-12-28 15:39:34 · 508 阅读 · 0 评论 -
Scala: Under The Hood of Hello World
The exercise of printing 'Hello World' from a new programming language is so popular because it allows you to see quite a few things about a language straight away, including the style of the syntax转载 2015-11-28 17:46:59 · 436 阅读 · 0 评论 -
Know Your Stack - Scala to Java to Bytecode to Assembly
Many times in my career so far I could have made better decisions, solved problems much faster or even prevented problems if I had a deeper understanding of the technology stack I was using.To b转载 2015-11-28 17:58:28 · 377 阅读 · 0 评论 -
Classes and Fields in Scala
Let’s take a very simple example of a class in Scala with one field:1classPerson{2 var name = ""3}Very concis转载 2015-11-28 17:04:04 · 499 阅读 · 0 评论 -
使用 maven 创建 scala 项目问题总结
使用maven创建scala项目,scala-archetype-simple有bug,会遇到一些问题,这里整理记录一下。我的环境是:maven 3.3.9eclipse 4.6java 1.8通过命令行的形式创建 scala项目:#mvn archetype:generate -B \ -DarchetypeGroupId=net.alchim31.maven -Da转载 2017-01-17 12:52:43 · 6901 阅读 · 0 评论