Kotlin和泛型,用泛型数组实现抽象泛型类(Kotlin and generics, implementing abstract generic class with generic array)
我有以下抽象类
abstract class Vec2t<T : Number>(open var x: T, open var y: T)
由...实施
data class Vec2(override var x: Float, override var y: Float) : Vec2t<Float>(x, y)
到目前为止,一切正常
现在,我想为矩阵做类似的事情,这是我的抽象类
abstract class Mat2t<T : Number>(open var value: Array<out Vec2t<T>>)
应该通过实施
class Mat2(override var value: Array<Vec2>) : Mat2t<Float>(value)
但编译器抱怨
Array<Vec2>
:错误:(8,32)Kotlin:'value'的类型与在main.mat.Mat2t中定义的重写的var-property'public open var value:Array>的类型不匹配'
有人告诉我:
- 当我覆盖它时,我无法更改
var
属性的类型(但实际上我并没有真正改变它,我用一个子类型覆盖它...是同样的事情吗?)mat2.value = object : Vec2t<Float>() { ... }
无效,Mat2t<Float>
任何子类都不一定如此我怎么能克服这些问题呢?
有没有办法让一个抽象的泛型类
Mat2t
与一个通用数组并用子类型数组实现它?I have the following abstract class
abstract class Vec2t<T : Number>(open var x: T, open var y: T)
implemented by
data class Vec2(override var x: Float, override var y: Float) : Vec2t<Float>(x, y)
So far, everything works just fine
Now, I'd like to do something similar for the matrices, this is at the moment my abstract class
abstract class Mat2t<T : Number>(open var value: Array<out Vec2t<T>>)
that should be implemented by
class Mat2(override var value: Array<Vec2>) : Mat2t<Float>(value)
But compiler complains on
Array<Vec2>
:Error:(8, 32) Kotlin: Type of 'value' doesn't match the type of the overridden var-property 'public open var value: Array> defined in main.mat.Mat2t'
I was told:
- I can't change the type of a
var
property when I override it (but actually I am not really changing it, I am overriding it with a subtype.. is it the same thing?)mat2.value = object : Vec2t<Float>() { ... }
would not be valid, which must not be the case for any subclass ofMat2t<Float>
How may I overcome these problems?
Is there a way to have an abstract generic class
Mat2t
with a generic array and implement it with a subtype array?
原文:https://stackoverflow.com/questions/40528739
最满意答案
没有任何
ORDER BY
不保证结果的顺序。您的问题现在被严重截断,但原始版本提到您在使用
nolock
和tablock
时看到了不同的结果顺序。这两个锁定选项都允许SQL Server使用分配顺序扫描,而不是按逻辑顺序沿着聚簇索引数据页读取(沿着链接列表的指针)。
这不应被视为保证订单处于聚簇索引顺序而不是高级扫描机制 ,或者例如并行性可以改变这一点。
Without any
ORDER BY
no order of results is guaranteed.Your question is now heavily truncated but the original version mentioned that you saw different order of result when using
nolock
as well astablock
.Both of these locking options allow SQL Server to use an allocation order scan rather than reading along the clustered index data pages in logical order (following pointers along the linked list).
That should not be taken as meaning that the order is guaranteed to be in clustered index order without that as the advanced scanning mechanism, or parallelism for example could both change this.
相关问答
更多-
没有功能差异,但最终没有WITH的语法将不起作用。 这已被弃用: select customer, zipcode from customers c (nolock) 所以你应该使用这种格式: select customer, zipcode from customers c with (nolock) 至少从SQL Server 2008开始不推荐使用WITH关键字作为表提示。搜索以下主题以获取Specifying table hints without using the WITH keywor ...
-
WITH(NOLOCK)相当于使用READ UNCOMMITED作为事务隔离级别。 因此,您可能会收到随后回滚的未提交的行的风险,即从未将其导入数据库的数据。 所以,虽然它可以防止读取被其他操作锁定,但却带来了风险。 在一个具有高交易率的银行业务应用程序中,它可能不是正在解决任何你想要解决的问题。 WITH (NOLOCK) is the equivalent of using READ UNCOMMITED as a transaction isolation level. So, you stand t ...
-
NOLOCK与Linq到SQL(NOLOCK with Linq to SQL)[2023-04-24]
是的,所以这里是我的博客中的条目: NOLOCK提示与将“隔离级别”设置为“未提交读取”的事务中包装查询基本相同。 这意味着查询并不在乎物件是否正在写入正在读取的行中 - 它会读取“脏”数据,并将其作为结果集的一部分返回。 原来,您可以使用.NET 2.0中引入的旧System.Transactions命名空间来完成整个“读取未提交”事务。 以下是一些示例代码: using (var txn = new TransactionScope( TransactionScopeOption.Require ... -
我不会解决READ UNCOMMITTED参数,只是你原来的问题。 是的,您需要在连接的每个表上WITH(NOLOCK) 。 不,你的查询是不一样的。 尝试这个练习。 开始事务并将一行插入到table1和table2中。 不要提交或回滚事务。 此时,您的第一个查询将成功返回并包含未提交的行; 您的第二个查询将不会返回,因为table2没有WITH(NOLOCK)提示。 I won't address the READ UNCOMMITTED argument, just your original ques ...
-
区别在于你应该使用语法WITH (NOLOCK) (或WITH (
) )。 为什么? 不WITH已弃用。 从MSDN上的表提示 : 省略WITH关键字是不推荐的功能:此功能将在未来版本的Microsoft SQL Server中删除。 避免在新开发工作中使用此功能,并计划修改当前使用此功能的应用程序。 from table1 nolock根本不适用 - 这是一个别名。 例如: SELECT nolock.name FROM sys.objects nolock ORDER B ... -
没有任何ORDER BY不保证结果的顺序。 您的问题现在被严重截断,但原始版本提到您在使用nolock和tablock时看到了不同的结果顺序。 这两个锁定选项都允许SQL Server使用分配顺序扫描,而不是按逻辑顺序沿着聚簇索引数据页读取(沿着链接列表的指针)。 这不应被视为保证订单处于聚簇索引顺序而不是高级扫描机制 ,或者例如并行性可以改变这一点。 Without any ORDER BY no order of results is guaranteed. Your question is now h ...
-
FREETEXTTABLE不支持表提示。 如果您希望在整个过程中进行未提交的读取(这是NOLOCK为单个表实现的),请在T-SQL中设置事务隔离级别: SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SELECT * FROM myTable AS FT_TBL FULL OUTER JOIN FREETEXTTABLE (myTable, fieldName, 'SRI') AS KEY_TBL ON FT_TBL.id = KEY_TBL ...
-
SQL Server NOLOCK提示是否会返回部分写入的行?(Will SQL Server NOLOCK hint return partially written rows?)[2022-09-12]
不可以 。插入,更新和删除等数据修改操作受低级物理锁存器保护。 所有数据访问操作(包括无锁SELECT)都必须符合锁存协议。 其结果是任何读者都不会看到部分写入。 No. Data modification operations like inserts, updates and deletes are protected by low level physical Latches. All data access operations, including lock-free SELECT, are ob ... -
NOLOCK和Coldfusion(NOLOCK and Coldfusion)[2024-01-27]
您的同事不正确, NOLOCK在上下文cftransaction之外并不是多余的。 如果使用SQL Server中的默认设置,则无论是否已明确键入,您执行的每个查询都将包含在事务中。 这称为“ 自动提交模式 ”。 Your co-worker in incorrect, NOLOCK is not redundant outside the context cftransaction. If you are using the default setting in SQL Server, every que ... -
sql-server-2005根据日期查询连续3天的第2条记录(sql-server-2005 query 2nd record of 3 consecutive days based on date)[2022-07-03]
经过几个小时的努力,我终于做到了。 如果有人需要它: WITH RESULTS AS( SELECT EVENTS.EMPID, CAST(DATEDIFF(d,0,EVENTS.EVENTIME) AS DATETIME) AS EVENTIME, COUNT(CAST(DATEDIFF(d,0,EVENTS.EVENTIME) AS DATETIME)) AS THIS_DAY FROM EVENTS INNER JOIN EMP ON EVENTS.EMPID = EMP.ID ...