warning: [unchecked] unchecked call to setCellValueFactory(Callback<CellDataFeatures<S,T>,ObservableValue<T>>) as a member of the raw type TableColumn column1.setCellValueFactory(new PropertyValueFactory<String, State>("name")); where S,T are type-variables:
S extends Object declared in class TableColumn
T extends Object declared in class TableColumn
Run Code Online (Sandbox Code Playgroud)
码:
column1.setCellValueFactory(new PropertyValueFactory<>("name"));
Run Code Online (Sandbox Code Playgroud)
warning: [unchecked] unchecked call to add(E) as a member of the raw type List
transitionTable.getColumns().add(column1);
where E is a type-variable:
E extends Object declared in interface List
Run Code Online (Sandbox Code Playgroud)
码:
transitionTable.getColumns().add(column1);
Run Code Online (Sandbox Code Playgroud)
warning: [unchecked] unchecked call to setAll(Collection<? extends E>) as a member of the …Run Code Online (Sandbox Code Playgroud) 该方法是否System.currentTimeMillis()实现为对底层操作系统进行系统调用以接收当前时间?
我问,因为据我所知,该方法运行速度非常快,只需6个CPU时钟,但这没有意义,因为已知系统调用很慢.
我在这里错过了什么?
我在Java spring MVC应用程序中将Hibernate Query Language(HQL)与Oracle数据库一起使用。我以这种方式编写了一个HQL更新查询:
String hql = "update " + MyModel.class.getName() + " e set e.field = " + value + " where ..."
//Acquiring session
...
Query query = session.createQuery(hql);
int result = query.executeUpdate();
Run Code Online (Sandbox Code Playgroud)
该executeUpdate()方法返回更新的行数。但是我想在执行更新查询后获取更新行的ID的列表。HQL有什么方法可以做到这一点吗?
我有一个基类和一个子类。在基类中,我有一个实例方法,它在__init__. 在子类中,我覆盖了这个方法。将super()在子类调用不会调用原始基本方法,但重写的子类的方法。为什么?
class BaseClass:
def __init__(self, value):
self.value = value
self.transformed_value = self.create_value(value)
def create_value(self, value):
print("base")
return value + 1
class SubClass(BaseClass):
def __init__(self, value):
super().__init__(value)
def create_value(self, value):
print("sub")
return value + 2
s = SubClass(3)
Run Code Online (Sandbox Code Playgroud)
我希望打印输出是“基本”,但实际输出是“子”。我如何修改代码即可获得“基地”没有显式调用BaseClass.create_value(self, value)中__init__的BaseClass?
给定一个包:
package/
??? __init__.py
??? module.py
Run Code Online (Sandbox Code Playgroud)
__init__.py:
from .module import function
Run Code Online (Sandbox Code Playgroud)
模块.py:
def function():
pass
Run Code Online (Sandbox Code Playgroud)
可以导入包并打印其命名空间。
python -c 'import package; print(dir(package))'
Run Code Online (Sandbox Code Playgroud)
['__builtins__', ..., 'function', 'module']
Run Code Online (Sandbox Code Playgroud)
题:
为什么仅在导入时package包含的命名空间?modulefunction__init__.py
我原以为package的命名空间将只包含function而不是module. 文档中也提到了这种机制,
“当使用任何机制(例如 importlib API、import 或 import-from 语句或内置
__import__())加载子模块时,将在父模块的命名空间中放置到子模块对象的绑定。”
但并没有真正的动机。对我来说,这个选择似乎很奇怪,因为我认为子模块是结构包的实现细节,并且不希望它们成为 API 的一部分,因为结构可以改变。
我也知道“Python 是为了成年人的同意”,并且不能真正向用户隐藏任何东西。但我会争辩说,将子模块名称绑定到包的范围会使用户不太清楚什么是 API 的实际组成部分以及什么可以更改。
为什么不使用__sub_modules__属性等来使用户可以访问子模块?这个设计决定的原因是什么?
我想写一些简单的东西
"{}MESSAGE{}".format("\t"*15, "\t"*15)
Run Code Online (Sandbox Code Playgroud)
使用
f"{'\t'*15}MESSAGE{'\t'*15}" # This is incorrect
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
"{}MESSAGE{}".format("\t"*15, "\t"*15)
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我是新手,对 Python 了解不多。有人知道如何在 while 循环中编写阶乘吗?
我可以在 if / elif else 语句中实现:
num = ...
factorial = 1
if num < 0:
print("must be positive")
elif num == 0:
print("factorial = 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print(num, factorial)
Run Code Online (Sandbox Code Playgroud)
但我想用一个 while 循环(无功能)来做到这一点。
我是python的新手,但对这个递归调用执行速度有多慢感到惊讶:
def daH(m:int):
if m == 1:
return int(1)
else:
if m <= .5 * (daH(m-1) * (daH(m-1) +1)):
return int(daH(m-1))
else:
return int(daH(m-1) + 1)
print(daH(10)) # prints 4
print(daH(11)) # prints 5
print(daH(15)) # prints 5
print(daH(16)) # prints 6
print(daH(106)) # prints ??? (gave up waiting)
Run Code Online (Sandbox Code Playgroud)
我在IDLE,python 3.6上运行它.我添加了INT的东西,但它没有帮助.运行标准阶乘递归和打印阶乘(106)没有问题.
这种递归尝试能否得到挽救?
我需要一个python函数(一个创建函数的函数),该函数为长度为N的列表创建所有循环排列运算符。
对于python列表a(例如a = [1, 2, 3, 4,5,6], N= 6),可以定义一个函数
def cyclic_perm(a):
n = len(a)
b = [[a[i - j] for i in range(n)] for j in range(n)]
return b
Run Code Online (Sandbox Code Playgroud)
这样就可以为列表提供所有可能的循环排列,在本例中为6个列表。
我希望函数不给我列表,而是(在这种情况下)6个运算符,当应用于列表时,每个运算符都给出一个排列的列表。
我做了一个嵌套字典
d = {
'first':{
'key': 'A',
'val': 1
},
'second':{
'key': 'A',
'val': 2
},
'third':{
'key': 'B',
'val': 5
},
'fourth':{
'key': 'B',
'val': 7
}
}
Run Code Online (Sandbox Code Playgroud)
现在假设我想创建一个嵌套字典的值列表,其中键为“key”。我的意思是,我想要一个这样的列表:
L = ['A', 'A', 'B', 'B']
Run Code Online (Sandbox Code Playgroud)
我设法在 for 循环和 value() 的帮助下以这种方式做到这一点:
List = d.values()
L = []
for K in List:
L.append(K['key'])
print(L)
Run Code Online (Sandbox Code Playgroud)
输出:
['A', 'A', 'B', 'B']
Run Code Online (Sandbox Code Playgroud)
但那里有更干净的东西吗?
python ×7
python-3.x ×3
java ×2
dictionary ×1
f-string ×1
factorial ×1
generics ×1
hibernate ×1
hql ×1
inheritance ×1
javafx ×1
jvm ×1
loops ×1
oracle ×1
recursion ×1
string ×1
super ×1
system-calls ×1
time ×1
unchecked ×1
warnings ×1
while-loop ×1