java 中getclass().getsimplename()_Java Class getSimpleName()方法

Java Class getSimpleName()方法

java.lang.Class.getSimpleName() 返回在源代码中给出底层类的简单名称。返回一个空字符串,如果底层类是匿名。

1 语法

public String getSimpleName()

2 参数

3 返回值

此方法返回底层类的简单名称。

4 示例

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

/**

* Java Class getSimpleName()方法

*/

import java.lang.*;

public class ClassDemo {

public static void main(String[] args) {

ClassDemo c = new ClassDemo();

Class cls = c.getClass();

// returns the name of the class

String name = cls.getName();

System.out.println("Class Name = " + name);

// returns the simple name of the class

String sname = cls.getSimpleName();

System.out.println("Class SimpleName = " + sname);

}

}

输出结果为:

Class Name = ClassDemo

Class SimpleName = ClassDemo

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Activity tempActivity = App.getMultiRoundActivity(); if (tempActivity != null && tempActivity instanceof MapBaseActivity) { ((MapBaseActivity) tempActivity).searchPoiWithLocationCheck(pi); }这个调用方法是, public void searchPoiWithLocationCheck(PoiSearchInfo poiSearchInfo) { this.mPoiSearchInfo = poiSearchInfo; Log.i(getClass().getSimpleName(), "searchPoiWithLocationCheck: "); mHandler.post(() -> { if (location_last_success_time == 0 || (System.currentTimeMillis() - location_last_success_time) > LOCATION_MAX_USE_TIME) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck , wait for location ready" + mLocClient); if (mToastLocating == null) { mToastLocating = Toast.makeText(MapBaseActivity.this, "正在定位,请稍后", Toast.LENGTH_LONG); } if (mLocClient == null) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : reInit location caused by null"); initLocation(); } else if (!mLocClient.isStarted()) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : restart location caused by stoped"); mLocClient.start(); } mIsPoiSearchNeeded = true; mToastLocating.show(); } else { searchPoi(poiSearchInfo); } }); 其,会走else,也就是searchPoi(poiSearchInfo);方法, public void searchPoi(PoiSearchInfo poiSearchInfo) { Log.i(getClass().getSimpleName(), "searchPoi: " + poiSearchInfo ); mIsPoiSearchNeeded = false; // 配置请求参数 附近检索 if (poiSearchInfo.getSearchType() == Constant.MAP_SEARCH_CITY){ searchInCity(poiSearchInfo); } else { searchNearBy(poiSearchInfo); } } 帮我修改一下这个调用方法的时候,要区分是哪一个行动,也就是去修改去目的地还是添加途经点
最新发布
05-30
根据您提供的代码,我看不出这个方法是用来修改目的地还是添加途经点的。不过,可以通过修改 `PoiSearchInfo` 对象的某些属性来区分是修改目的地还是添加途经点。具体来说,您可以添加一个 `boolean` 类型的属性来表示是否为目的地,然后在调用 `searchPoiWithLocationCheck` 方法时,根据这个属性来决定是调用修改目的地的方法还是添加途经点的方法。例如: ``` public void searchPoiWithLocationCheck(PoiSearchInfo poiSearchInfo) { this.mPoiSearchInfo = poiSearchInfo; Log.i(getClass().getSimpleName(), "searchPoiWithLocationCheck: "); mHandler.post(() -> { if (location_last_success_time == 0 || (System.currentTimeMillis() - location_last_success_time) > LOCATION_MAX_USE_TIME) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck , wait for location ready" + mLocClient); if (mToastLocating == null) { mToastLocating = Toast.makeText(MapBaseActivity.this, "正在定位,请稍后", Toast.LENGTH_LONG); } if (mLocClient == null) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : reInit location caused by null"); initLocation(); } else if (!mLocClient.isStarted()) { Log.i(MapBaseActivity.this.getClass().getSimpleName(), "searchPoiWithLocationCheck : restart location caused by stoped"); mLocClient.start(); } mIsPoiSearchNeeded = true; mToastLocating.show(); } else { if (poiSearchInfo.isDestination()) { modifyDestination(poiSearchInfo); } else { addWaypoint(poiSearchInfo); } } }); } ``` 其,`PoiSearchInfo` 对象可以定义为如下所示: ``` public class PoiSearchInfo { private boolean isDestination; // 是否为目的地 private int searchType; // 搜索类型 // 其他属性 // 构造方法 // Getter 和 Setter } ``` 这样,就可以通过 `isDestination` 属性来区分不同的行为。对应的修改目的地和添加途经点的方法可以根据实际需求自行编写。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值