If rsPeriod.Fields(0) Is Nothing Then
TurnoverPTD = 0
Else
TurnoverPTD = rsPeriod.Fields(0)
End If
现在当我尝试使用它时:
private float xCoOrdinate, yCoOrdinate;
private double screenCenterX, screenCenterY;
Ide不会枚举任何方法,我无法添加适当的phpdoc。 我总是把它包起来:
mRrootLayout.getBackground().setAlpha(255);
/**
* Calculate max hypo value and center of screen.
*/
final DisplayMetrics display = getResources().getDisplayMetrics();
screenCenterX = display.widthPixels / 2;
screenCenterY = (display.heightPixels - getStatusBarHeight()) / 2;
final double maxHypo = Math.hypot(screenCenterX, screenCenterY);
mImageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
/**
* Calculate hypo value of current imageview position according to center
*/
double centerYPos = mImageView.getY() + (mImageView.getHeight() / 2);
double centerXPos = mImageView.getX() + (mImageView.getWidth() / 2);
double a = screenCenterX - centerXPos;
double b = screenCenterY - centerYPos;
double hypo = Math.hypot(a, b);
/**
* change alpha of background of layout
*/
alpha = (int) (hypo * 255) / (int) maxHypo;
if (alpha < 255)
mRrootLayout.getBackground().setAlpha(255 - alpha);
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
xCoOrdinate = mImageView.getX() - event.getRawX();
yCoOrdinate = mImageView.getY() - event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
mImageView.animate().x(event.getRawX() + xCoOrdinate).y(event.getRawY() + yCoOrdinate).setDuration(0).start();
break;
case MotionEvent.ACTION_UP:
if (alpha > 50) {
Toast.makeText(ImageViewerActivity.this, "Out", Toast.LENGTH_SHORT).show();
return false;
} else {
Toast.makeText(ImageViewerActivity.this, "In", Toast.LENGTH_SHORT).show();
mImageView.animate().x(0).y((float) screenCenterY - mImageView.getHeight() / 2).setDuration(100).start();
mRrootLayout.getBackground().setAlpha(255);
}
default:
return false;
}
return true;
}
});
但这并非100%令人满意,特别是当我有大量这些时。
答案 0 :(得分:1)
如果工厂可以返回不同类的实例,那么所有这些类都应该实现一个通用接口。在这种情况下,您不应该关心实际的类,而是使用此接口。
如果创建的对象应该有不同的方法(通用接口不能覆盖),那么显然工厂应该为每种类型的对象(甚至是单独的工厂)都有单独的方法。
如果您真的需要具有不同类型返回值的方法,如果类型安全性无关紧要并且您只想要IDE自动完成,那么只需添加doc-comment with multiple types如下(PHPStorm和NetBeans支持此表示法):
/**
* …
*
* @return A|B|C
*/