初级会员
  • 第 18864 位会员
  • zgjff
  • 2018-05-24 09:58:56
  • Offline
  • 21 74

最近发布的主题

    暂无

最近发布的文章

    暂无

最近分享的资源

    暂无

最近发布的项目

    暂无

最近的评论

  • 总感觉强制类型转换用这个面试题不太合理。。。。。 ``` func main() { w := worker{job{baseWage: 6000}} printYearMoney(&w) f := farmer{job{baseWage: 4000}} printYearMoney(&f) wa := waiter{job{baseWage: 5000}} printYearMoney(&wa) t := teacher{job: job{6000}, dailyWage: 100} printYearMoney(&t) s := scientist{job: job{20000}, yearWage: 50000} printYearMoney(&s) } type money float64 func (m money) String() string { return fmt.Sprintf("%.2f元", m) } type yearMoney interface { annualSalary() money } func printYearMoney(y yearMoney) { fmt.Println(y, "的年薪为:", y.annualSalary()) } type job struct { baseWage money } func (j *job) annualSalary() money { return j.baseWage * 12 } type worker struct { job } func (w worker) String() string { return "工人" } type farmer struct { job } func (f farmer) String() string { return "农民" } type waiter struct { job } func (w waiter) String() string { return "服务生" } type teacher struct { job dailyWage money } func (t teacher) String() string { return "教师" } func (t *teacher) annualSalary() money { return t.baseWage*12 + t.dailyWage*180 } type scientist struct { job yearWage money } func (s scientist) String() string { return "科学家" } func (s *scientist) annualSalary() money { return s.baseWage*12 + s.yearWage } ```
  • struct 内部自带锁应该好些吧 type User struct { Cash int lock *sync.Mutex }
  • zguijie1005@163.com 谢谢楼主,前端想转后端,不知道如何下手,就缺实战了