将一种类型的对象转换成目标类型的对象,提供给需要的目标对象使用
/**
* Create by pengQun 2021/2/26
* Desc:220V电源提供者
*/
public class Power220V {
private static final String TAG = Power220V.class.getSimpleName();
public Power220V() {
Log.d(TAG,"---> 我是220V的电源 ");
}
}
/**
* Create by pengQun 2021/2/26
* Desc:使用5V电源充电的手机
*/
public class Phone5V {
private static final String TAG = Phone5V.class.getSimpleName();
public Phone5V() {
Log.d(TAG, "---> 手机:需要5V的电源充电 ");
}
public void inputPower(int power) {
Log.d(TAG, "---> 手机:正在使用" + power + "V电源充电");
}
}
/**
* Create by pengQun 2021/2/26
* Desc:5V电源适配器
*/
public class PowerAdapter {
private static final String TAG = PowerAdapter.class.getSimpleName();
public int exchangedPower(Power220V power220V) {
Log.d(TAG, "---> 适配器:将220V电源转化成5V的电源 ");
return 5;
}
}













网友评论