我认为问题标题有点令人困惑,但我无法找到更准确的方式来说明这一点。
我只需要一个简单的代码示例来告诉你我想要什么。
我有:
// code 1
interface A { A bla(); }
class B implements A { @Override public B bla() { return this; } }
class C implements A { @Override public C bla() { return this; } }
但实际上,这段代码也会编译(diff:查看返回类型声明):
// code 2
interface A { A bla(); }
class B implements A { @Override public A bla() { return this; } }
class C implements A { @Override public A bla() { return this; } }
我希望代码2是类型错误
说,我想强制每个A
的子类' bla
方法返回自己,而不是A
。
我认为可能有一个假代码来代表我想要的东西:
interface A { this.Type bla(); }
就像Haskell的类型类:
class Monad (m :: * -> *) where
-- here m is restricted to the subclass
(>>=) :: m a -> (a -> m b) -> m b
这可能吗?
答案 0 :(得分:3)
不可能,但你可以这样做
import sys
import cx_Freeze
import os.path
import scipy
base = None
if sys.platform == 'win32':
base = "Win32GUI"
#This part may depend on where your installation is
#This part is essential to copy the tkinter DLL files over
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
os.environ['REQUESTS_CA_BUNDLE'] = r'C:\ProgramData\Anaconda3\Lib\site-packages\botocore\vendored\requests\cacert.pem'
executables = [cx_Freeze.Executable("test.py", base=base)]
addtional_mods = ['numpy.core._methods', 'numpy.lib.format']
packages = ["idna", "numpy", "boto3", 'boto3.s3.transfer', 'boto3.s3.inject', 'multiprocessing', "xlwt", 'numpy.core._methods', 'pandas']
options = {
'build_exe': {
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.dirname(scipy.__file__),
r'C:\ProgramData\Anaconda3\Lib\site-packages\botocore\vendored\requests\cacert.pem',
r'C:\ProgramData\Anaconda3\Lib\site-packages\botocore',
],
'includes': addtional_mods,
'packages':packages,
},
}
cx_Freeze.setup(
name = "Test",
options = options,
version = "1.0.0.0",
description = 'Test',
executables = executables
)