Skip to content

Commit 9f722dd

Browse files
committed
Add @transparentTrait annotation for use in Scala 2
1 parent 1f744af commit 9f722dd

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

docs/docs/reference/other-new-features/transparent-traits.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ appear in the inferred type.
3636
### Transparent Traits
3737

3838
The traits `scala.Product`, `java.lang.Serializable` and `java.lang.Comparable`
39-
are treated automatically as transparent. Other traits can be turned into transparent traits,
40-
by adding the modifier `transparent` in front of `trait`, as shown above.
39+
are treated automatically as transparent. Other traits are turned into transparent traits using the modifier `transparent`. Scala 2 traits can also be made transparent
40+
by adding a `@transparentTrait` annotation. This annotation is defined in `scala.annotation`. It will be deprecated and phased out once Scala 2/3 interopability is no longer needed.
4141

42-
Every trait can be declared as transparent. Typically, transparent traits are traits
42+
Typically, transparent traits are traits
4343
that influence the implementation of inheriting classes and traits and that are not usually used as types by themselves. Two examples from the standard collection library:
4444

4545
- `IterableOps`, which provides method implementations for an `Iterable`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scala.annotation
2+
3+
/** An annotation that can be used from Scala 2 to mark a trait as transparent.
4+
* Scala 3 code would use the modifier `transparent` instead. Transparent traits
5+
* are not inferred when combined with other types in an intersection.
6+
* See reference/other-new-features/transparent-traits.html for details.
7+
*/
8+
final class transparentTrait extends StaticAnnotation

0 commit comments

Comments
 (0)