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.

29 questions
143
votes
9 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,629
  • 2
  • 13
  • 9
33
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
  • 473
  • 1
  • 4
  • 8
6
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 …
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
  • 5,820
  • 13
  • 51
  • 102
3
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,142
  • 7
  • 23
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
  • 593
  • 4
  • 12
  • 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
  • 8,115
  • 1
  • 21
  • 37
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
  • 40,403
  • 57
  • 174
  • 291
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,191
  • 13
  • 51
  • 91
2
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 doesnt give me a clear picture to me. Now i have a small piece of code shown below: subtype Element4_Range is…
maddy
  • 787
  • 2
  • 9
  • 18
1
vote
0 answers

Lists and unchecked conversions

In trying to fix a warning about "Type safety: The expression of type List needs unchecked conversion to conform to List". Basically taking a List of Objects and casting it to a List of InventoryPDFAdapter. This was the code which was throwing the…
1
2