Skip to content

Commit fbd4859

Browse files
committed
Docs
1 parent 16852fd commit fbd4859

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
@@ -103,6 +103,8 @@ sidebar:
103103
url: docs/reference/dropped-features/type-projection.html
104104
- title: Procedure Syntax
105105
url: docs/reference/dropped-features/procedure-syntax.html
106+
- title: Package Objects
107+
uril: docs/reference/dropped-features/package-objects.html
106108
- title: Early Initializers
107109
url: docs/reference/dropped-features/early-initializers.html
108110
- title: Class Shadowing

0 commit comments

Comments
 (0)