Tanvi
Tanvi

Reputation: 413

How to assign enum type arguement in scala

object StorageType extends Enumeration{
    type Name = Value
    val HTML, TEXT, SUBJECT = Value
  }

def read(key:String, _type:StorageType.Value = StorageType.HTML):String = {
    val accessKey = getPrefix(_type) + key
    DaoFactory.getPreviewStorageDao.get(accessKey).data
  }

Does this mean I can only send StorageType.HTML as argument and not StorageType.SUBJECT? Also I am pretty new to scala so can you tell me what exactly does _type do here?

Upvotes: 0

Views: 60

Answers (1)

Ryoichiro Oka
Ryoichiro Oka

Reputation: 1997

The _type parameter can be any one of the StorageType.Value instances, but if you don't put any instance into it when you call the method, then the StorageType.HTML instance will be automatically assigned.

Upvotes: 2

Related Questions