The path dependent types
In scala, you can have abstract types, which will be instantiated/specialized in subclasses. such as follow.
class Outter {
class Inner {
}
}
and in the repl, you type
val o1 = new Outer
val o2 = new Outer
new o1.Inner
resl1: o1.Inner = Outter$Inner@ldf6ed6
the resulting inner object will contain a reference to its outer object, the object references from o1. Because the type Outer#Inner does not name any specific instance of outer, you can't create an instance of it
scala > new Outer#Inner
<Console> 7 : error : outer is not a legal prefix for a constructor
new Outer#Inner
so that means that in scala because the type can be an abstract member of an abstract class, Object.InnerType has a concrete type, while the static class notation, Outer.Iner may/may not have the necessary type information.
the Outer#Inner notation is much like the java Outer.Inner notation, let's take a close look at how the java nested class works.
The magic Outer.this symbol
since it is a rule that the inner class can access the outer class's instance. but this requires a bit, since it is highly possible that the inner may have a member which has the same field as the outer class.
how to disambiguate the inner class and the outer class? here is an example.
public class InnerClassTest {
public static void main(String[] args) {
new OutterClass().doIt();
}
}
class OutterClass {
private String m_outterClassMember = null;
public OutterClass() {
m_outterClassMember = "Hello world";
}
public void doIt() {
new InnerClass().sayHello();
}
public void enclosingClassMethod(String arg) {
System.out.println(arg);
}
class InnerClass {
public void sayHello() {
OutterClass.this.enclosingClassMethod(OutterClass.this.m_outterClassMember);
}
}
}
分享到:
相关推荐
赠送jar包:scala-java8-compat_2.11-0.7.0.jar; 赠送原API文档:scala-java8-compat_2.11-0.7.0-javadoc.jar; 赠送源代码:scala-java8-compat_2.11-0.7.0-sources.jar; 赠送Maven依赖信息文件:scala-java8-...
赠送jar包:scala-java8-compat_2.11-0.7.0.jar; 赠送原API文档:scala-java8-compat_2.11-0.7.0-javadoc.jar; 赠送源代码:scala-java8-compat_2.11-0.7.0-sources.jar; 赠送Maven依赖信息文件:scala-java8-...
Learn Scala is split into four parts: a tour of Scala, a comparison between Java and Scala, Scala-specific features and functional programming idioms, and finally a discussion about adopting Scala in...
本示例着重讲解如何在Java和Scala之间进行互调用,这是基于Maven构建系统的。Maven是Apache开发的项目管理工具,它可以帮助开发者管理项目的构建、依赖关系以及文档的生成。在Java和Scala的混合开发环境中,Maven...
**Scala集合与Java开发:深度解析与经验技巧** 在编程世界中,Scala和Java是两种广泛应用的编程语言,尤其在企业级应用开发中占据重要地位。Scala,作为一门多范式编程语言,融合了面向对象和函数式编程的特性,为...
scala-java8-compat Scala的Java 8兼容性套件。 该API目前仍处于试验阶段:我们尚不能保证与将来的版本保持源代码或二进制兼容性。 Javadoc在。 Scala功能的功能接口 一组用于scala.FunctionN的。 这些设计用于...
Scala for Java Developers is a step-by-step guide full of easy-to-follow code taken from real-world examples explaining the migration and integration of Scala in a Java project. With this book, you ...
Then, we will provide a comparative analysis of Java and Scala. Finally, we will dive into Scala programming to get started with Scala. Chapter 2, Object-Oriented Scala, says that the object-oriented ...
在现代软件开发中,Java和Scala是两种广泛使用的编程语言。它们各有特色,Java以其稳定性和广泛的社区支持而著名,Scala则以其强大的函数式编程特性及对Java虚拟机(JVM)的无缝集成受到青睐。当一个项目中同时包含...
在Jelastic平台上使用Scala进行Java开发是一个独特而高效的方法,特别是在多语言支持和云环境优化方面。Jelastic是一个高度自动化的、针对Java和PHP应用的PaaS(平台即服务)解决方案,它允许开发者以容器为基础进行...
Scala and Spark for Big Data Analytics by Md. Rezaul Karim English | 25 July 2017 | ISBN: 1785280848 | ASIN: B072J4L8FQ | 898 Pages | AZW3 | 20.56 MB Harness the power of Scala to program Spark and ...
本书介绍Scala基本语法、构造。以及如何将您已经知道的复制java语法转换为Scala,了解Scala除了javabecome之外还提供了哪些功能编程概念和惯用技巧和建议,这些技巧和建议在将现有java项目转换为Scala时非常有用
项目概述:《深入解析Scala与Java共筑的Spark全面学习源码》 本项目以Scala为主要开发语言,辅以Java实现,全面讲解了Spark的原理与应用。包含文件共150个,其中主要包括: - XML配置文件:139个,为项目提供了...
本资源提供了一套基于Scala和Java的Spark大数据处理平台的设计源码,包含14244个文件,其中包括4014个Scala源代码文件,1559个Q文件,1009个文本文件,983个Java源代码文件,488个Python脚本文件,403个SQL文件,...
Scala到Java 用Scala编写的简单工具,揭示了Scala编译器的奥秘。 从StdIn读取scala代码,并将其反编译的Java版本写入StdOut。 用法 确保您已安装Java 1.8和Maven 检出项目 在项目目录中调用mvn clean package 。 ...
本项目是基于Scala和Java开发的Spark学习项目设计源码,主要使用Scala进行开发。项目共包含576个文件,其中Scala源代码文件scala 533个,Java源代码文件java 21个,XML配置文件xml 10个,Properties配置文件...
"编排基于微服务的流程_Scala_Java_下载.zip"这个压缩包文件很可能包含了一个关于如何使用Scala和Java来设计和实施微服务流程的项目或教程。下面,我们将深入探讨微服务架构、Scala和Java在微服务中的应用,以及流程...
这里我们将详细探讨如何使用Scala和Java来实现简体与繁体中文的互换以及判断文字是简体还是繁体。 首先,让我们了解简体和繁体中文的区别。简体中文是20世纪50年代以来在中国大陆广泛使用的标准化汉字形式,特点是...