class A
{
}
class B : A
{
}
void method(A that is not a B argument) {}
void generic_method(generic_class<A that is not a B> generic_argument) {}
void params_method(params A that is not a B[] params_arguments) {}
Run Code Online (Sandbox Code Playgroud)
有没有任何语法方法来做到这一点?我意识到我可以做到
if(argument is B)
throw new ArgumentException("argument cannot be a B", "argument");
Run Code Online (Sandbox Code Playgroud)
在第一个方法的开头,并在foreach中为第二个和第三个方法执行此操作,但我想知道是否有一些关键字或OOP概念可以更好地完成此操作.
在哈斯克尔工作,发现奇怪的行为,将其剥离为裸骨
这个作品
a :: Bool
a = case True of
True -> True
False -> False
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试
b :: IO Bool
b = do
let b' = case True of
True -> True
False -> False
return b'
Run Code Online (Sandbox Code Playgroud)
我明白了
ghci>:l test.hs
[1 of 1] Compiling Main ( test.hs, interpreted )
test.hs:16:14: parse error on input ‘->’
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)
所以我试试
c :: IO Bool
c = do
let c' = case True of
True -> True
False -> False …Run Code Online (Sandbox Code Playgroud) 考虑以下python脚本
#!/usr/bin/env python
from Tkinter import Tk, Label
width = SOME_VALUE_HERE
root = Tk()
label1 = Label(root, text='1 columns wide')
label2 = Label(root, text='%i columns wide' % width)
label1.grid()
label2.grid(row=0,column=1,columnspan=width)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
当我运行它时,无论为“SOME_VALUE_HERE”设置什么值,两个标签都占据窗口的一半,无论是否调用了 Grid.columnconfigure,或者是否在 grid() 中使用了粘性参数。
除非我忽略了一些东西,否则我会认为设置 columnspan 会强制第二个标签的宽度是第一个标签的 'SOME_VALUE_HERE' 倍。
我误解了网格的工作原理吗?我将如何实现这种行为?