吐槽 你们知道土拨鼠的梗嘛?

2018-01-29 13:32:13 +08:00
 sandao

《 Thinking in Java 》的 Containers in Depth 一章的 Hashing and hash codes 有这么一段演示代码: 一个天气系统,将 Groundhog (土拨鼠)对象和 Prediction (预报)对象联系起来。

代码本身很简单,但是看的时候是不是一脸懵逼?ヽ( ̄д ̄;)ノ为什么土拨鼠和天气预报有关?

土拨鼠日(英语:Groundhog Day ),是北美地区的一个传统节日。每年 2 月 2 日,美国和加拿大许多城市和村庄都会庆祝。自从 1887 年以来,一代又一代的土拨鼠一直担负着预报时令的任务。根据传说,如果土拨鼠能看到它自己的影子,那么北美的冬天还有 6 个星期才会结束。如果它看不到影子,春天不久就会来临。-----摘自维基百科

俏丽奶奶ಥ_ಥ

最后推荐下《土拨鼠之日》这部电影(´°ᗜ°)ハハッ

//: containers/Groundhog.java
    // Looks plausible, but doesn ’ t work as a HashMap key.
    public class Groundhog {
      protected int number;
      public Groundhog(int n) { number = n; }
      public String toString() {
        return "Groundhog #" + number;
      }
} ///:~
//: containers/Prediction.java
    // Predicting the weather with groundhogs.
    import java.util.*;
    public class Prediction {
      private static Random rand = new Random(47);
      private boolean shadow = rand.nextDouble() > 0.5;
      public String toString() {
        if(shadow)
          return "Six more weeks of Winter!";
        else
          return "Early Spring!";
}
} ///:~
//: containers/SpringDetector.java
    // What will the weather be?
    import java.lang.reflect.*;
    import java.util.*;
    import static net.mindview.util.Print.*;
    public class SpringDetector {
      // Uses a Groundhog or class derived from Groundhog:
      public static <T extends Groundhog>
      void detectSpring(Class<T> type) throws Exception {
        Constructor<T> ghog = type.getConstructor(int.class);
        Map<Groundhog,Prediction> map =
          new HashMap<Groundhog,Prediction>();
        for(int i = 0; i < 10; i++)
          map.put(ghog.newInstance(i), new Prediction());
        print("map = " + map);
        Groundhog gh = ghog.newInstance(3);
        print("Looking up prediction for " + gh);
        if(map.containsKey(gh))
          print(map.get(gh));
        else
          print("Key not found: " + gh);
      }
      public static void main(String[] args) throws Exception {
        detectSpring(Groundhog.class);
10604 次点击
所在节点    Java
20 条回复
anguslg
2018-01-29 13:37:11 +08:00
我是在看完<源代码>和<明日边缘>之后看的<土拨鼠之日>, 看到你的标题我第一想到的就是这个电影
taisenjay
2018-01-29 13:44:57 +08:00
涨了一波知识,666
sandao
2018-01-29 13:49:34 +08:00
@anguslg 我也是诶,源代码我记得我还是高中跑去学校一个人把投影仪打开看的,当时觉得除了男演员其他演员都好省事(´°ᗜ°)ハハッ
jerry12547
2018-01-29 14:00:43 +08:00
这个前几天我在知乎上看到过,他们还养着那个土拨鼠来着,然后市长还会过来庆祝。。
pusidun
2018-01-29 15:06:04 +08:00
不是说,有一次土拨鼠预测错了,还被起诉了?
QAPTEAWH
2018-01-29 15:07:57 +08:00
土拨鼠:啊~~~~~~
imn1
2018-01-29 15:11:19 +08:00
土拨鼠:None of my businese !
sandao
2018-01-29 15:13:37 +08:00
@pusidun 是的,心疼无辜的土拨鼠Ծ ̮ Ծ
ReVanTis
2018-01-29 15:15:10 +08:00
土拨鼠发来贺电
sandao
2018-01-29 15:15:19 +08:00
@QAPTEAWH 画面感很强(´°ᗜ°)ハハッ
oswuhan
2018-01-29 15:17:19 +08:00
@QAPTEAWH #6 第一时间想起来的就是这个梗
paloalto
2018-01-29 15:23:40 +08:00
wyntalgeer
2018-01-29 15:38:41 +08:00
不是报错了一次判了死刑
tedzhou1221
2018-01-29 15:59:24 +08:00
@wyntalgeer 后来好像土拨鼠的支持者提起上诉了!哈哈
SingeeKing
2018-01-29 16:04:12 +08:00
土拨鼠…… 我前女友外号。。
MontagePa
2018-01-29 16:49:45 +08:00
问题是,来年春天发现土拨鼠,会顺带把他们吃掉啊。
sandao
2018-01-29 16:59:07 +08:00
@MontagePa 能怎好?噢,不,好吃吗?
boywang004
2018-01-29 17:05:44 +08:00
这个梗的确之前不知道……好吧。
Anybfans
2018-01-29 17:36:08 +08:00
!()[ ]
roricon
2018-01-29 18:22:16 +08:00
@paloalto 我首先想到的也是这个图.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/426778

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX