Questions tagged [unchecked-conversion]

The `unchecked` keyword is in .NET used to suppress overflow-checking for integral-type arithmetic operations and conversions.

In an unchecked context, if an expression produces a value that is outside the range of the destination type, the overflow is not flagged.

More info with examples on MSDN.

31 questions
154
votes
10 answers

How do I fix "The expression of type List needs unchecked conversion...'?

In the Java snippet: SyndFeedInput fr = new SyndFeedInput(); SyndFeed sf = fr.build(new XmlReader(myInputStream)); List entries = sf.getEntries(); the last line generates the warning "The expression of type List needs unchecked…
user46277
  • 1,739
  • 2
  • 13
  • 10
40
votes
5 answers

unchecked -keyword in C#

Maybe I'm in the basics, but I'm still studying this C# thing at school. I understand that if I add 1 to max valued Integer, which one is 32 bit, the result will be negative. I read that C# offers checked and unchecked keywords for handling…
Jere_Sumell
  • 543
  • 1
  • 4
  • 8
7
votes
2 answers

How to suppress overflow-checking in PowerShell?

PowerShell seems to perform bounds-checking after arithmetic operations and conversions. For instance, the following operations fail: [byte]$a = 255 $a++ $a = [byte]256 Is there any way to enforce overflows or the typecast without resorting to a…
5
votes
1 answer

How to remove Spring CrudRepository unchecked conversion beside using suppress annotation

This is my code : public interface UserRepo extends CrudRepository { boolean exist(Long id); @Override User save(User user); } In eclipse, there is a warning on the return type User. Description Resource Path …
user3832050
  • 53
  • 1
  • 4
4
votes
2 answers

Unchecked cast from X to generic type that extends X

I've been tasked with removing as many @SupressWarnings as possible in our codebase, and I'm not sure how to get around this particular issue. I have this external method that returns a Serializable object, and a generic type T extends Serializable…
mario_sunny
  • 1,412
  • 11
  • 29
4
votes
3 answers

Type safety with generics

I have a bunch of simple interfaces: interface County extends Line{} interface Country extends LineContainer {} interface Line {} interface LineContainer { public List getLines(); } And a Service…
Kaos
  • 41
  • 1
4
votes
6 answers

How can I safely downsize a long to an int?

According to the question, "Can I convert long to int?", the best way in C# to convert a long to an int is: int myIntValue = unchecked((int)myLongValue); How can I do this in VB.NET? VB.NET does not have the concept of unchecked to my…
Hoppe
  • 6,508
  • 17
  • 60
  • 114
3
votes
3 answers

Suppress warnings for unchecked conversion

I have this piece of code : with Ada.Unchecked private package MyPackage is function UC_Bool_To_U8 is new Ada.Unchecked_Conversion (Source => Boolean, Target => T_U8); end MyPackage; Where T_U8 is : type T_U8 is range 0 .. 2**7; Function…
A.Pissicat
  • 3,023
  • 4
  • 38
  • 93
3
votes
2 answers

Unchecked_Conversion in Ada

Can anyone please make me clear about the use of unchecked conversion in the Ada language.I had tried the pdf and net but all doesn't give me a clear picture to me. Now I have a small piece of code shown below: subtype Element4_Range is integer…
maddy
  • 827
  • 2
  • 11
  • 19
3
votes
1 answer

The expression of type List needs unchecked conversion to conform to List, when using Hibernate Criteria

I have this piece of code that gives the warning mentioned in the title: List studentList = session.createCriteria(Student.class) .add(Restrictions.eq("indexNumber", indexNum)) .list(); I've read the thread How do I fix "The…
just_a_girl
  • 643
  • 4
  • 13
  • 28
3
votes
2 answers

Fix "unchecked conversion found" warning in Java?

As a project for university, I am writing a Java program that takes classes derived from a Player class and stores them in a Club class. The Club is a cricket club (hence the variable/class names). The class below is still only partially built but…
2
votes
2 answers

Using Unchecked_Conversion to read in values and convert to a custom type

I'm quite confused on how 'Size and 'Component_Size work when reading input from a file and trying to use Unchecked_Conversion. I know that to sucsessfully use Unchecked_Conversion both the Source and the Target need to be the same size. I'm reading…
Mikel
  • 93
  • 8
2
votes
3 answers

Generic method performs implicit cast while non-generic method needs explicit cast

This question is related to a previous question. The original can be solved by adding casts to do unchecked conversions. So now I have the following code: import java.util.EnumSet; class A { static enum E1 { X } private static
Jens
  • 9,058
  • 2
  • 26
  • 43
2
votes
1 answer

Avoiding unsafe cast for generic situation involving runtime passing of class

public class AutoKeyMap { public interface KeyGenerator { public K generate(); } private KeyGenerator generator; public AutoKeyMap(Class keyType) { // WARNING: Unchecked cast from…
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
2
votes
3 answers

Type safety: The expression of type List needs unchecked conversion to conform to Collection

I'm using set for defining allowed keys for some action. Eclipse shows this warning: Type safety: The expression of type List needs unchecked conversion to conform to Collection I googled a bit and found same message in…
user1097772
  • 3,499
  • 15
  • 59
  • 95
1
2 3