首先是,Go里没有继承的概念,只有“实现某interface”的概念
其次是,没有办法获取到所有实现了某个interface的struct。即使你找到了所有的列举在switch-case语句里,如果有人在他自己package里写了个struct实现了Run方法,调用你的函数会发生什么呢?
看你的需求,好像实现一个OneOf类型。可惜Go里实现不了…
--
--
官网: http://golang-china.org/
IRC: irc.freenode.net #golang-china
@golangchina
---
您收到此邮件是因为您订阅了Google网上论坛上的“Golang-China”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到golang-china...@googlegroups.com。
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/golang-china/CABsaAAk5aStVdxqOcx7ba4%3Dp4J20RQSnFACiO2HcaHFEhfV7ig%40mail.gmail.com。
要查看更多选项,请访问https://groups.google.com/d/optout。
首先是,Go里没有继承的概念,只有“实现某interface”的概念
其次是,没有办法获取到所有实现了某个interface的struct。即使你找到了所有的列举在switch-case语句里,如果有人在他自己package里写了个struct实现了Run方法,调用你的函数会发生什么呢?
看你的需求,好像实现一个OneOf类型。可惜Go里实现不了…
On Dec 30, 2014 7:35 AM, "Setter Guo" <sette...@gmail.com> wrote:
Hi,如果我定义一个interface I和它相应的actions:type I interface {Run()}那么所有有Run()的struct都应该是I的继承类。我如何找到全部的I的继承类呢?主要写像下面code的时候你不能漏了:Exec(x I) {switch y := x.(type) {case *X:...case *Y:...}...}希望不要吐槽,大家好好讨论。谢谢!Best Regards,Setter--
--
官网: http://golang-china.org/
IRC: irc.freenode.net #golang-china
@golangchina
---
您收到此邮件是因为您订阅了Google网上论坛上的“Golang-China”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到golang-china+unsubscribe@googlegroups.com。
是仅调用你接受的interface定义的函数,不对传入类型再做更多假设。
当然还有一些interface promotion的技巧可以type assertion尝试将参数转换为另一接口类型,不过和你的代码关系不大
>>> 要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到golang-china...@googlegroups.com。
>>> 要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/golang-china/CABsaAAk5aStVdxqOcx7ba4%3Dp4J20RQSnFACiO2HcaHFEhfV7ig%40mail.gmail.com。
>>> 要查看更多选项,请访问https://groups.google.com/d/optout。
>
> --
> --
> 官网: http://golang-china.org/
> IRC: irc.freenode.net #golang-china
> @golangchina
> ---
> 您收到此邮件是因为您订阅了Google网上论坛上的“Golang-China”群组。
> 要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到golang-china...@googlegroups.com。
> 要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/golang-china/6373d5a7-7fde-4a17-9271-80218c249cde%40googlegroups.com。
> 要查看更多选项,请访问https://groups.google.com/d/optout。
是仅调用你接受的interface定义的函数,不对传入类型再做更多假设。
>>> 要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到golang-china+unsubscribe@googlegroups.com。
>>> 要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/golang-china/CABsaAAk5aStVdxqOcx7ba4%3Dp4J20RQSnFACiO2HcaHFEhfV7ig%40mail.gmail.com。
>>> 要查看更多选项,请访问https://groups.google.com/d/optout。
>
> --
> --
> 官网: http://golang-china.org/
> IRC: irc.freenode.net #golang-china
> @golangchina
> ---
> 您收到此邮件是因为您订阅了Google网上论坛上的“Golang-China”群组。
> 要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到golang-china+unsubscribe@googlegroups.com。
看看 go oracle 这个工具是否符合你的要求
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到golang-china...@googlegroups.com。
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/golang-china/20173512-980f-4321-9246-f163a795dc37%40googlegroups.com。
要查看更多选项,请访问https://groups.google.com/d/optout。