- 浏览: 141582 次
-
最新评论
-
xlaohe1:
controller返回的是一个POJO对象,然后用@Resp ...
Spring MVC 4.X ResponseBody 日期类型Json 处理 -
TRAMP_ZZY:
能帮到你,我也很高兴。
Spring MVC 4.X ResponseBody 日期类型Json 处理 -
jobzjc:
第一段有帮到我。如果是非对象,Object方式传递的时候,第一 ...
Spring MVC 4.X ResponseBody 日期类型Json 处理 -
TRAMP_ZZY:
dingran 写道为什么,我怎么就没找到System > ...
Ubuntu 12.04 设置 IBus 开机启动 -
dingran:
为什么,我怎么就没找到System >> Pref ...
Ubuntu 12.04 设置 IBus 开机启动
文章列表
当有数个对象的集合,它们彼此之间有“整体/部分”的关系,并且你想用一致的方法对待这些对象,就需要用到组合模式。
public abstract class MenuComponent {
public void add(MenuComponent menuComponent) {
throw new UnsupportedOperationException();
}
public void remove(MenuComponent menuComponent) {
throw new UnsupportedOperationException();
...
public class LinkedStack<T> {
private static class Node<U> {
U item;
Node<U> next;
Node() {item = null; next = null;}
Node(U item, Node<U> next) {
this.item = item;
this.next = next;
}
boolean end() {
return item == null && next == ...
1.简单代理模式
interface Interface {
void doSomething();
void somethingElse(String arg);
}
class RealObject implements Interface {
@Override
public void doSomething() {
System.out.println("doSomething");
}
@Override
public void somethingElse(String arg) {
System.out. ...
public class InputFile {
private BufferedReader in;
public InputFile(String fname) throws Exception {
try {
in = new BufferedReader(new FileReader(fname));
} catch (FileNotFoundException e) {
e.printStackTrace();
throw e;
} catch (Exception e) {
try {
in.close() ...
public class ReversibleArrayList<T> extends ArrayList<T> {
public ReversibleArrayList(Collection<T> c) {
super(c);
}
public Iterable<T> reversed() {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return new Iter ...
Class A实现接口CallBack callback——背景1
class A中包含一个class B的引用b ——背景2
class B有一个参数为callback的方法f(CallBack callback) ——背景3
1. 异步的回调机制
public interface CallBack {
public abstract void solve(String result);
}
public class Wang implements CallBack {
private Li li;
public Wang(Li li) {
thi ...
public interface Service {
void method1();
void method2();
}
public interface ServiceFactory {
Service getService();
}
public class Implementation1 implements Service {
@Override
public void method1() {
}
@Override
public void method2() {
}
public static ServiceF ...
当生成一个内部类的对象时,此对象与制造它的外围对象就有了一种联系。所以其能访问
其外围对象的所有成员,而不需要任何特殊条件。此外,内部类还拥有其外围类的所有元素的
访问权。
在拥有外部类对象之前是不可能创建内部类对象的。这是因为内部类对象会暗暗地连接到它的外部类对象上。
但是,如果你创建时嵌套类(静态内部类),那么它就不需要对外部对象的引用。
public class DotThis {
void f() {
System.out.println("DotThis.f()");
}
public class Inner {
...
迭代器模式提供一种方法顺序访问一个聚合对象中的各个元素,而又不暴露其内部的表示。
public interface Aggregate<E> {
Iterator<E> createIterator();
}
public class ConcreteAggregate implements Aggregate<Object> {
Object[] object;
public ConcreteAggregate(Object[] object) {
this.object = object;
}
@ ...
public class RandomWords implements Readable {
private static Random rand = new Random(47);
private static final char[] capticals =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
private static final char[] lowers =
"abcdefghijklmnopqrstuvwxyz".toCharArray();
...
1. Java 中的Enum 默认的都是继承自java.lang.Enum<> 类,该类如下:
public abstract class Enum<E extends Enum<E>>
implements Comparable<E>, Serializable {
/**
* The name of this enum constant, as declared in the enum declaration.
* Most programmers should use the {@l ...
可以直接跳出到标签位置。从多层循环中。
Java 里需要使用标签的唯一理由就是因为有循环嵌套的存在,而且想从多层嵌套中break
或continue
public class LabelFor {
public static void main(String[] args) {
int i = 0;
outer:
for (; i < 10; i++) {
System.out.println("i = " + i);
if (i == 2) {
System.out.println("cont ...
public class BeanCopyUtils {
/**
*
* copy:<br />
* 复制一个对象到另外一个
*
* @author zhangzhaoyu
* @param object
* @return
* @throws Exception
*/
public static void copy(Object org, Object des) throws Exception {
Class<?> orgClassType = org.getClass();
Cl ...
public abstract class CaffeineBeverage {
public final void prepareRecipe() {
boilWater();
brew();
pourInCup();
addCondiments();
}
abstract void brew();
abstract void addCondiments();
void boilWater() {
System.out.println("Boiling water.");
}
void po ...
int x = 0x2f; // 十六进制
int y = 0712; // 八进制
int z = 12; // 十进制
// 二进制显示整数
Integer.toBinaryString(i);
Long.toBinaryString(i);
移位操作符操作的运算对象也是二进制的位。移位操作符只用来处理整数类型。
左移位(<<)能按照操作符指定的位数将操作符左边的操作数向左移动(在低位补0)
有符号右移位操作符(>>)则按照操作符右侧指定的位数将操作符左边的操作数向右移动。若符号为正,则在高位插入0,若为负,则插入1。Java 中增加了无符号右移操作(&g ...