在Java片段中:
SyndFeedInput fr = new SyndFeedInput();
SyndFeed sf = fr.build(new XmlReader(myInputStream));
List<SyndEntry> entries = sf.getEntries();
Run Code Online (Sandbox Code Playgroud)
最后一行生成警告
"类型的表达式List需要未经检查的转换以符合List<SyndEntry>"
有什么方法可以解决这个问题?
也许我是基础知识,但我还在学校学习这个C#的东西.据我所知,如果我将1加到最大值整数,哪一个是32位,结果将是负数.我读到C#提供了检查和未检查的关键字来处理溢出.已检查的关键字是一种东西,我发现它很有用,但未经检查的关键字怎么样?我真的找不到用于unchecked -keyworded块的有用的东西.有没有?接下来的两种方法如何相互不同?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice_6
{
class Program
{
static void Main(string[] args)
{
int value = Int32.MaxValue;
value++;
//Approach 1 to make a decision
if (value > Int32.MaxValue) {
//Do something
}
value = Int32.MaxValue;
//Approach 2 to make a decision
unchecked {
value++;
//Do something
}
//What's the difference between these two approaches to handle overflow?
}
}
Run Code Online (Sandbox Code Playgroud) PowerShell 似乎在算术运算和转换后执行边界检查。例如,以下操作失败:
[byte]$a = 255
$a++
$a = [byte]256
Run Code Online (Sandbox Code Playgroud)
有没有办法强制溢出或类型转换,而无需通过模或 C# 和 Add-Type 进行手动计算?
这是我的代码:
public interface UserRepo extends CrudRepository<User, Long> {
boolean exist(Long id);
@Override
User save(User user);
}
Run Code Online (Sandbox Code Playgroud)
在eclipse中,返回类型User有一个警告。
说明 资源路径 位置 类型 类型安全:类型 UserRepo 的 save(User) 的返回类型 User 需要未经检查的转换以符合类型 CrudRepository UserRepo.java 中的 S
我可否知道
质量保证
根据问题," 我可以将long转换为int吗? ",C#将long转换为int的最佳方法是:
int myIntValue = unchecked((int)myLongValue);
Run Code Online (Sandbox Code Playgroud)
我怎么能在VB.NET中做到这一点?根据我的理解,VB.NET没有未经检查的概念.
当我在转换器中转换代码时,它说使用CInt().但是CInt抛出了一个system.overflowexception.在C#中使用unchecked会阻止system.overflowexception.
我宁愿不抓住异常.
Dim x As Long = Int32.MaxValue
x = x + 100
Console.WriteLine(x)
Dim y As Integer = CInt(x)
Console.WriteLine(y)
Run Code Online (Sandbox Code Playgroud) 作为一个大学项目,我正在编写一个Java程序,它接受从Player类派生的类并将它们存储在一个Club类中.俱乐部是一个板球俱乐部(因此变量/类名称).下面的类仍然只是部分构建,但它编译并且在我需要解决的问题上足够完整.编译下面的类时,我收到两个'未经检查'的警告:
import java.util.*;
public class Club{
private String name;
private List<Player> players;
private Set<Player> playersAverage;
private int regID;
@SuppressWarnings(value = {"unchecked"})
public Club(){
this.name = "";
this.players = new ArrayList<Player>();
this.playersAverage = new TreeSet<Player>(new BattingAverageComparator());
this.regID = 1;
}
@SuppressWarnings(value = {"unchecked"})
public Club(String name){
this.name = name;
this.players = new ArrayList<Player>();
this.playersAverage = new TreeSet<Player>(new BattingAverageComparator());
this.regID = 1;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public boolean registerPlayer(Player player) throws …Run Code Online (Sandbox Code Playgroud) java unchecked compiler-warnings unchecked-conversion comparator
我有这段代码:
with Ada.Unchecked
private package MyPackage is
function UC_Bool_To_U8 is new Ada.Unchecked_Conversion (Source => Boolean, Target => T_U8);
end MyPackage;
Run Code Online (Sandbox Code Playgroud)
T_U8 在哪里:
type T_U8 is range 0 .. 2**7;
Run Code Online (Sandbox Code Playgroud)
功能UC_Bool_To_U8 正在运行,但我有编译警告:
警告:未经检查的转换类型具有不同的大小
警告:“Boolean”的大小为 1,“T_U8”的大小为 8
警告:源将扩展为 7 个高阶零位
我怎样才能抑制这些警告?
我正在使用 set 来定义某些操作的允许键。Eclipse 显示此警告:
Type safety: The expression of type List needs unchecked conversion
to conform to Collection<? extends Object>
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了一下,在略有不同的情况下发现了相同的消息,但可能是类似的问题。
有没有机会以其他方式摆脱这个警告
@SuppressWarnings("unchecked")
Run Code Online (Sandbox Code Playgroud)
是个好主意
@SuppressWarnings("unchecked")
Run Code Online (Sandbox Code Playgroud)
在这种情况下?
这是我的代码:
public static final String KEY_A = "A_VALUE";
public static final String KEY_B = "B_VALUE";
public static final Set<?> allowedKeys = new HashSet<Object>(Arrays.asList(new String[] {KEY_A, KEY_B}));
Run Code Online (Sandbox Code Playgroud) 我很困惑如何'Size以及'Component_Size从文件中读取输入的工作时,并尝试使用Unchecked_Conversion。我知道要成功使用Unchecked_ConversionSource和Target都必须相同size。我正在从类似文件的输入中读取内容,000100000101001并希望使用未经检查的转换将其放入Bits数组中。但是,由于它们大小不一样或太小,因此转换似乎总是失败。
with Ada.Unchecked_Conversion;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure main is
type Bit is mod 2 with size => 1;
type Bit_Array is array(Positive range <>) of Bit with pack;
subtype Bit15 is Bit_Array(1 .. 15); //subtypes because can't use conversion on unconstrainted type
subtype Bit11 is Bit_Array(1 .. 11);
function StringA_to_Bit15 is
new Ada.Unchecked_Conversion(source => String, target => Bit15);
begin
while not end_of_file loop …Run Code Online (Sandbox Code Playgroud) 谁能解释一下 ada.unchecked_coversion(float, UnsignedInteger) 的操作。这个操作会执行什么?谁能用例子来澄清这一点。预先非常感谢。
ada ×3
java ×3
c# ×2
unchecked ×2
warnings ×2
c#-4.0 ×1
collections ×1
comparator ×1
powershell ×1
spring ×1
spring-data ×1
vb.net ×1