Go的接口如何工作?(How exactly do interfaces work in Go?)
在阅读了规范和他们的“Effective Go”部分之后,我仍然不太明白Go中的接口是如何工作的。
像,你在哪里定义它们? 界面实施如何工作? 有没有一种方法来指定某个对象实现接口的地方,而不是简单地在接口中定义方法?
对初学者问题抱歉; 但我真的很难理解这一点。
After reading the spec, and the "Effective Go" section on them, I still don't quite understand how interfaces work in Go.
Like, where do you define them? How does interface enforcement work? And is there a way to specify somewhere that an object implements an interface, as opposed to simply defining the methods in the interface?
Apologies for the beginner question; but I really am struggling to understand this.
原文:https://stackoverflow.com/questions/3126605
最满意答案
您至少有两个选择:
case $menu_answer in [Aa]) optionA ;; B|b) optionB ;; *) echo Oops ;; esac
您也可以考虑
select
菜单,而不是case
。You have two options at least:
case $menu_answer in [Aa]) optionA ;; B|b) optionB ;; *) echo Oops ;; esac
Instead of
case
, you could also considerselect
for a menu.
相关问答
更多-
BigDecimal乘以零(BigDecimal multiply by zero)[2022-04-27]
你不能使用equals()方法来比较BigDecimals ,就像这个断言一样。 这是因为这等于功能将比较比例 。 如果比例不同,则equals()将返回false,即使它们是数学上相同的数字。 但是您可以使用compareTo()来执行所需的操作: 正如@assylias指出的,你也应该使用new BigDecimal("22.3")构造函数来避免双重精度问题。 BigDecimal expected = BigDecimal.ZERO; BigDecimal actual = new BigDecima ... -
如果你有bash str1="MATCH" str2="match" shopt -s nocasematch case "$str1" in $str2 ) echo "match";; *) echo "no match";; esac 否则你应该告诉我们你正在使用哪个shell。 替代,使用awk str1="MATCH" str2="match" awk -vs1="$str1" -vs2="$str2" 'BEGIN { if ( tolower(s1) == tolower(s2) ) ...
-
按照惯例,环境变量( PAGER , EDITOR ,..)和内部shell变量( SHELL , BASH_VERSION ,..)被大写。 所有其他变量名应为小写。 记住变量名是区分大小写的; 这个惯例避免了意外地超越环境和内部变量。 遵守此约定,您可以放心,您不需要知道UNIX工具或shell使用的每个环境变量,以避免覆盖它们。 如果它是您的变量,请小写。 如果你导出它,大写它。 By convention, environment variables (PAGER, EDITOR, ...) and ...
-
您至少有两个选择: case $menu_answer in [Aa]) optionA ;; B|b) optionB ;; *) echo Oops ;; esac 您也可以考虑select菜单,而不是case 。 You have two options at least: case $menu_answer in [Aa]) optionA ;; B|b) optionB ;; *) echo Oops ;; esac Instead of cas ...
-
如果构建失败,Jenkins不会执行shell脚本(Jenkins doesn't execute shell scripts in case of build failure)[2024-04-11]
您应该能够使用Any Build Step Plugin实现此目的。 使用它来运行脚本作为构建后操作。 如任何构建步骤插件页面中所述,它似乎也需要灵活的发布插件 ,以允许运行任何构建步骤作为构建后操作。 You should be able to achieve this with Any Build Step Plugin. Use it to run your script as post-build action. As stated in Any Build Step Plugin page, it ... -
在bash中,你可以使用 shopt -s nocaseglob In bash, you can use shopt -s nocaseglob
-
感谢用户user2357112的评论,我已经解决了这个问题。 我在这里发布了代码,用于遇到类似问题的人。 (C) static PyObject *demo_multiply(PyObject *self, PyObject *args) { float y[2]; float x; if (!PyArg_ParseTuple(args, "ff", &(y[0]), &(y[1]))) return NULL; x = y[0] * y[1]; return Py ...
-
您需要将配置ajax请求的服务器配置为不区分大小写。 您无法在客户端中更改服务器的区分大小写(除了提供服务器期望的情况)。 Your server fielding the ajax request will need to be configured to NOT be case sensitive. There is nothing you can do in the client to change case sensitivity of a server (other than providing ...
-
如果我没有错,那么双引号中“期望”的任何参数都会被花括号替换。 因此,expect命令变得像: expect ssh_exec.expect oracle@192.168.***.*** {srvctl status database -d mydb} 这使得shell将“{srvctl”解释为命令。 尝试使用它像这样: EXPECT_OUTPUT=($(expect ssh_exec.expect $*)) 代替 EXPECT_OUTPUT=($(expect ssh_exec.expect $1 $ ...
-
使用具有多个输出的函数(非汇总fxn?)并进行汇总(Using the function with multiple outputs (non-summary fxn?) with summarize)[2023-07-03]
library(data.table) setDT(df)[,opt(.SD), by=type] type V1 1: A -0.07686590 2: D 0.10719041 3: D 0.11553210 4: D 0.13909786 5: B 0.16122635 6: B 0.18304797 7: C -0.08671413 其中opt是削减的功能: opt <- function(df) optimal.cutp ...