Java之getSimpleName()的作用

public class Sample{
  public static void main(String[] args){
    //得到类的简写名称
    System.out.println(Sample.class.getSimpleName());
 
   //得到对象的全路径
   System.out.println(Sample.class);
 
   //得到对象的类模板示例,也就是Class
   System.out.println(Sample.class.getClass());
 
   //得到Class类的名称
   System.out.println(Sample.class.getClass().getName());
 } 
}

打印结果为:

Sample

class com.lovo.test.Sample

class java.lang.Class

java.lang.Class

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
protostuff 是一个支持各种格式的一个序列化Java类库,包括 JSON、XML、YAML等格式。示例代码:public class UserSchema implements Schema<User> {     public boolean isInitialized(User user)     {         return user.getEmail() != null;     }     public void mergeFrom(Input input, User user) throws IOException     {         while(true)         {             int number = input.readFieldNumber(this);             switch(number)             {                 case 0:                     return;                 case 1:                     user.setEmail(input.readString());                     break;                 case 2:                     user.setFirstName(input.readString());                     break;                 case 3:                     user.setLastName(input.readString());                     break;                 case 4:                     if(message.friends == null)                         message.friends = new ArrayList<User>();                     message.friends.add(input.mergeObject(null, this));                     break;                 default:                     input.handleUnknownField(number, this);             }         }     }     public void writeTo(Output output, User user) throws IOException     {         if(user.getEmail() == null)             throw new UninitializedMessageException(user, this);         output.writeString(1, user.getEmail(), false);         if(user.getFirstName() != null)             output.writeString(2, user.getFirstName(), false);         if(user.getLastName() != null)             output.writeString(3, user.getLastName(), false);         if(message.friends != null)         {             for(User friend : message.friends)             {                 if(friend != null)                     output.writeObject(4, friend, this, true);             }         }     }     public User newMessage()     {         return new User();     }     public Class<User> typeClass()     {         return User.class;     }     public String messageName()     {         return User.class.getSimpleName();     }     public String messageFullName()     {         return User.class.getName();     }     // the mapping between the field names to the field numbers.     public String getFieldName(int number)     {         switch(number)         {             case 1:                 return "email";             case 2:                 return "firstName";             case 3:                 return "lastName";             case 4:                 return "friends";             default:                 return null;         }     }     public int getFieldNumber(String name)     {         Integer number = fieldMap.get(name);         return number == null ? 0 : number.intValue();     }     private static final HashMap<String,Integer> fieldMap = new HashMap<String,Integer>();         static     {         fieldMap.put("email", 1);         fieldMap.put("firstName", 2);         fieldMap.put("lastName", 3);         fieldMap.put("friends", 4);     } } 标签:protostuff

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值