tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Spring > Expression Language > Types

Types 

The Spring Expression Language (SpEL) is a simple and powerful expression language which helps to query and manipulate objects at runtime. The following example shows accessing java types such as class, interface and enums using SpEL. The T operator is used to get a reference to specified type.

File Name  :  
com/bethecoder/tutorials/spring3/tests/spel/TypesTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.spring3.tests.spel;

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

public class TypesTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    ExpressionParser parser = new SpelExpressionParser();
    Class clazz = parser.parseExpression("T(Integer)").getValue(Class.class);
    System.out.println(clazz);
    
    clazz = parser.parseExpression("T(Boolean)").getValue(Class.class);
    System.out.println(clazz);

    clazz = parser.parseExpression("T(char)").getValue(Class.class);
    System.out.println(clazz);

    clazz = parser.parseExpression("T(java.util.List)").getValue(Class.class);
    System.out.println(clazz);

    clazz = parser.parseExpression("T(java.util.Vector)").getValue(Class.class);
    System.out.println(clazz);

    clazz = parser.parseExpression("T(Void)").getValue(Class.class);
    System.out.println(clazz);
    
  }
}
   

It gives the following output,
class java.lang.Integer
class java.lang.Boolean
char
interface java.util.List
class java.util.Vector
class java.lang.Void



 
  


  
bl  br