假设我运行以下代码将片段放入堆栈.它设置了我最初查看片段时以及何时退出片段的动画.
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_left,
R.anim.no_anim,
R.anim.no_anim_show,
R.anim.slide_right_away);
fragmentTransaction.replace(R.id.container, fragment, tag);
fragmentTransaction.addToBackStack(tag);
fragmentTransaction.commit();
Run Code Online (Sandbox Code Playgroud)
如果我想稍后更改退出动画,我该怎么办呢?如同,如果我有以下代码:
getFragmentManager().popBackStack();
Run Code Online (Sandbox Code Playgroud)
但我想要一个不同的动画,然后是我最初放入堆栈的动画.
我相信我犯了一个非常简单的错误/忽略了一些微不足道的事情.
import java.util.Comparator;
public class NaturalComparator<Integer> {
public int compare(Integer o1, Integer o2) {
return o1.intValue() - o2.intValue();
}
}
Run Code Online (Sandbox Code Playgroud)
编译时收到以下错误.
NaturalComparator.java:6: error: cannot find symbol
return o1.intValue() - o2.intValue();
^
symbol: method intValue()
location: variable o1 of type Integer
where Integer is a type-variable:
Integer extends Object declared in class NaturalComparator
NaturalComparator.java:6: error: cannot find symbol
return o1.intValue() - o2.intValue();
^
symbol: method intValue()
location: variable o2 of type Integer
where Integer is a type-variable:
Integer extends Object declared …Run Code Online (Sandbox Code Playgroud) 假设我有一些使用数组存储值的堆栈实现.弹出时,可以简单地更改我的"指针"值所指的位置,还是应该将当前数组位置设置为null?
public T pop() {
size--;
return stack[size];
}
Run Code Online (Sandbox Code Playgroud)
与
public T pop() {
size--;
T result = stack[size];
stack[size] = null;
return result;
}
Run Code Online (Sandbox Code Playgroud) public int example1(int a, int b) {
if (a > b) {
return true;
} else {
return false;
}
}
public int example2(int a, int b) {
if (a > b) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这两个功能是否有首选标准?如同在这样的函数中,"if"是否应该始终跟在"else"之后?
编辑:例如,我看到如下定义的等于?你们有些人说你会删除"其他"吗?
public boolean equals(Object otherObject)
{
if (otherObject == null)
return false;
else if (getClass() != otherObject.getClass())
return false;
else
{
MyClass otherMyClass = (MyClass) otherObject;
return (variable.equals(otherMyClass.variable));
}
}
Run Code Online (Sandbox Code Playgroud)