🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators typename
Created by Alexandra on 2017-08-13 · Last edited by Sandra.akech on 2025-12-12.


Returns the data type information of an object as a string.

String.typeName

Returns

System.String

Example:

vStringValue:String='SomeString'
vStringValue.OclType.typeName

Returns

System.String

OclType.asString returns the same value as typeName.


Asking a variable X:

let X = 2

“What kind of thing are you?”“Are you a String? Are you an Integer? Are you a Boolean?”

typeName answers that question.

The typeName operator in OCL is helpful for several reasons:

  • It helps verify that a value has the expected type.
  • It's useful in debugging, as you can check the type of values during development.
  • It's valuable when writing generic functions or expressions that need to work on many kinds of data.
  • It helps confirm model behavior during validation by ensuring types are used correctly.
  • It ensures expressions behave as expected, especially when values may be null or dynamically computed, by allowing you to inspect their types at runtime.

See also: