Yu Gu
Yu Gu

Reputation: 2493

What does the bracket [ ] mean when it comes after a class name?

For example,

class BasicTransitionFunction(TransitionFunction[GrammarBasedState]):
      ...

where TransitionFunction is the base class of BasicTransitionFunction, and GrammarBasedState is also a class name. I only know that [] can be used to indexed arrays. What does it mean here?

Upvotes: 6

Views: 496

Answers (1)

Arusekk
Arusekk

Reputation: 881

This is the syntax for generic types. Like @Sraw said, it means that TransitionFunction is a generic type. For example, List is a generic type, so you can have List[Int].

This is the same idea as for C++ templates (e.g. std::vector<int>).

So here BasicTransitionFunction is a subclass of a TransitionFunction between GrammarBasedStates.

Upvotes: 1

Related Questions