Skip to content

Commit 5b90688

Browse files
committed
Docs
1 parent 359b80f commit 5b90688

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
layout: doc-page
3+
title: Dropped: Package Objects
4+
---
5+
6+
Package objects
7+
```scala
8+
package object p {
9+
val a = ...
10+
def b = ...
11+
}
12+
```
13+
will be dropped. They are still available in Scala 3.0, but will be deprecated and removed afterwards.
14+
15+
Package objects are no longer needed since all kinds of definitions and statements can now be written at the top-level. E.g.
16+
```scala
17+
package p
18+
val a = ...
19+
def b = ...
20+
```
21+
There may be several source files in a package containing such toplevel definitions, and source files can freely mix toplevel value, method, and tyoe definitions with classes and objects.
22+
23+
The compiler generates synthetic objects that wrap toplevel statements that are not imports, or class or object definitions. If a source file `src.scala` contains such toplevel statements, they will be put in a synthetic object named `src#object`. The wrapping is transparent, however. The definitions in `f` can still be accessed
24+
as members of the enclosing package.

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ sidebar:
116116
url: docs/reference/dropped-features/type-projection.html
117117
- title: Procedure Syntax
118118
url: docs/reference/dropped-features/procedure-syntax.html
119+
- title: Package Objects
120+
uril: docs/reference/dropped-features/package-objects.html
119121
- title: Early Initializers
120122
url: docs/reference/dropped-features/early-initializers.html
121123
- title: Class Shadowing

0 commit comments

Comments
 (0)