Slice

@SerialVersionUID(1L)
final class Slice extends CharSequence with Serializable

Character sequence representing a lazily-calculated substring.

This class has three constructors:

  • Slice(s) wraps a string, ensuring that future operations (e.g. subSequence) will construct slices instead of strings.

  • Slice(s, start, limit) is the default, and ensures that:

  1. start >= 0 2. limit >= start 3. limit <= s.length
  • Slice.unsafe(s, start, limit) is for situations where the above bounds-checking has already occurred. Only use this if you are absolutely sure your arguments satisfy the above invariants.

Slice's subSequence returns another slice. This means that when wrapping a very large string, garbage collection on the underlying string will not occur until all slices are freed.

Slice's universal equality is only defined with regard to other slices. This means comparing a Slice with other CharSequence values (including String) will always return false.

Slices are serializable. However! They use the default Java serialization layout, which is not that efficient, and could be a disaster in cases where a large shared string might be serialized many times in different slices.

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def charAt(i: Int): Char
override def equals(that: Any): Boolean
Definition Classes
Any
override def hashCode: Int
Definition Classes
Any
def subSequence(i: Int, j: Int): Slice
override def toString: String
Definition Classes

Inherited methods

Inherited from:
CharSequence
Inherited from:
CharSequence

Concrete fields

final val length: Int