我想做燕子
我想做燕子
只需简单思想
只求风中流浪
我想做树
不长六腑五脏
不会寸断肝肠
我做不成燕子
所以我
躲不过感情的墙
我做不成树
因此也
撑不破伤心的网
来生做燕子吧
随意找棵树休息翅膀
然后淡然飞向远方
来生做树吧
枝头的燕子飞走时
不去留恋地张望
···小雨康桥
把诗转化成代码
今生:
创建生物接口
/**
* 生物
* @author jackfrued
*
*/
public interface Creature {
}
燕子 接生物接口
public class Swallow implements Creature {
/**
* 简单思想
*/
public void thinkSimply() {
System.out.println("简单思想");
}
/**
* 风中流浪
*/
public void wanderInWind() {
System.out.println("风中流浪");
}
}
树 接生物接口
public class Tree implements Creature {
public void toBeHeartless() {
System.out.println("不长六腑五脏");
System.out.println("不会寸断肝肠");
}
}
我
public class I implements Creature {
}
测试代码
public class Test01 {
public static void main(String[] args) {
Creature i = new I();
if(i instanceof Swallow) {
((Swallow) i).thinkSimply();
((Swallow) i).wanderInWind();
}
else {
System.out.println("飞不过感情的墙");
}
if(i instanceof Tree) {
((Tree) i).toBeHeartless();
}
else {
System.out.println("撑不破伤心的网");
}
}
}
以上是今生的版本
下面的来世的版本
生物接口
/**
* 生物
* @author
*
*/
public interface Creature {
}
燕子 接生物接口
public interface Swallow extends Creature {
/**
* 简单思想
*/
public void thinkSimply();
/**
* 风中流浪
*/
public void wanderInWind();
}
树 接生物接口
public interface Tree extends Creature {
public void toBeHeartless();
}
我
public class I implements Tree, Swallow {
@Override
public void thinkSimply() {
System.out.println("随意找棵树休息翅膀");
}
@Override
public void wanderInWind() {
System.out.println("淡然飞向远方");
}
@Override
public void toBeHeartless() {
System.out.println("当枝头燕子飞去时,再不用留恋张望");
}
}
测试代码
public class Test01 {
public static void main(String[] args) {
Creature i = new I();
if(i instanceof Swallow) {
((Swallow) i).thinkSimply();
((Swallow) i).wanderInWind();
}
else {
System.out.println("飞不过感情的墙");
}
if(i instanceof Tree) {
((Tree) i).toBeHeartless();
}
else {
System.out.println("撑不破伤心的网");
}
}
}