This question already has an answer here:

I have recently started using generic methods in my projects. I am working on a chess project where every piece class extends to Pieces.java.

Diagram of my pieces package

And in the Player.java, I have added this code:

public class Player {
    Pieces[] pieces = new Pieces[16];
    Player() {
        …
        init();
    }
    private void init() {
        //initialize pieces array with all pieces.
        pieces[0] = new Pawn(new Point(6, 0), this);
        pieces[1] = new Pawn(new Point(6, 1), this);
        pieces[2] = new Pawn(new Point(6, 2), this);
        pieces[3] = new Pawn(new Point(6, 3), this);
        pieces[4] = new Pawn(new Point(6, 4), this);
        pieces[5] = new Pawn(new Point(6, 5), this);
        pieces[6] = new Pawn(new Point(6, 6), this);
        pieces[7] = new Pawn(new Point(6, 7), this);
        pieces[8] = new Rook(new Point(7, 0), this);
        pieces[9] = new Knight(new Point(7, 1), this);
        pieces[10] = new Bishop(new Point(7, 2), this);
        pieces[11] = new Queen(new Point(7, 3), this);
        pieces[12] = new King(new Point(7, 4), this);
        pieces[13] = new Bishop(new Point(7, 5), this);
        pieces[14] = new Knight(new Point(7, 6), this);
        pieces[15] = new Rook(new Point(7, 7), this);
    }
    public <T extends Pieces> T getPiece(Point point) {
        for(Pieces piece: pieces) {
            if(piece.isAlive() && piece.getCurrentPoint().equals(point))
                return (T)piece;
        }
        return null;
   }
}

But now, IntelliJ gives me a warning, "Unchecked cast from "Pieces" to T. Even when I mentioned that and all the elements of pieces array is a subclass of Pieces, even then IntelliJ gives me a warning: "Unchecked cast from Pieces to T". How am I supposed to fix this.

Please do not mark this as duplicate because the answer of other questions have not helped me.

I am getting an unchecked cast warning and I am not sure if it is safe to suppress it.

I am putting a ArrayList inside a Bundle. This Bundle is then put in my Intent as following:

Intent mIntent = new Intent(getBaseContext(),MySecondActivity.class);
            Bundle myBundle = new Bundle();
            myBundle.putSerializable("fragmentList",ArrayList<Fragment>);
            mIntent.putExtras(myBundle);
            startActivity(mIntent);

Then on my new activity (MySecondActivity) I am retrieving this data with the following code:

(ArrayList<Fragment>) getIntent().getSerializableExtra("fragmentList")

My compiler gives me a " Unchecked cast: 'java.io.Serializable' to 'java.util.ArrayList' " warning. Everything is working fine though, am I right to say I can safely suppress it ?

Thank you!

I use @SuppressWarnings("unchecked") and @SuppressWarnings("null") mostly above methods to let the code compile without any warnings but I have my doubts. Found this Stackoverflow question. Jon Skeet wrote an answer to it which I find intriguing.

According to him,

Sometimes Java generics just doesn't let you do what you want to, and you need to effectively tell the compiler that what you're doing really will be legal at execution time.

But what if there is a chance that an exception will be thrown? Isn't suppressing warnings a bad idea then? Shouldn't I be aware of the places where problems could surface?

Also, what if someone else modifies my code later and adds some questionable functionality without removing SuppressWarnings? How can that be avoided and/or is there any other alternative to this?

Should I be using @SuppressWarnings("unchecked") and @SuppressWarnings("null")?


Update

As far as unchecked type casts go, according to this answer (pointed out by @gnat in the comments below), suppressing these warnings is necessary.

Many indispensible Java libraries have never been updated to eliminate the need for unsafe typecasts. Suppressing those warnings is necessary so that other more important warnings will be noticed and corrected.

I have some problem to release app

When i rebuild App there is no problem, problem is when i want to get release Version

Inside App Gradle file :

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }



    packagingOptions {
        exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
    }
    defaultConfig {
        applicationId "com.prject.app"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        def getLastHashComit = 'git rev-parse --short HEAD'.execute().text.trim();
        versionName versionCode.toString() + "_" + getLastHashComit
    }


    buildTypes {
        buildTypes {
            debug {
                minifyEnabled true  // shrink
                useProguard true    // obfuscate

                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }

            release {
                minifyEnabled true  // shrink
                useProguard true    // obfuscate

                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }

        }
    }

}
ext.supportLibraryVersion = '25.0.0'
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile "com.android.support:support-v4:25.0.0"
    compile "com.android.support:design:25.0.0"
    compile "com.android.support:support-annotations:25.0.0"
    compile "com.android.support:recyclerview-v7:25.0.0"
    compile "com.android.support:cardview-v7:25.0.0"
    compile "com.android.support:percent:25.0.0"
    //Retrofit
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    //OkHttp
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'com.squareup.okio:okio:1.7.0'
    //Gson
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.1'
    //RxJava
    compile 'io.reactivex:rxjava:1.1.2'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
    compile 'com.danikula:videocache:2.6.3'
    compile 'com.hannesdorfmann:swipeback:1.0.4'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'

    compile 'com.balysv:material-ripple:1.0.2'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'jp.wasabeef:glide-transformations:2.0.1'
    compile 'com.github.hotchemi:permissionsdispatcher:2.3.0'
    compile 'me.zhanghai.android.materialratingbar:library:1.0.2'
    compile 'com.akexorcist:RoundCornerProgressBar:2.0.3'
    compile 'com.aurelhubert:ahbottomnavigation:2.0.4'
    compile 'pub.devrel:easypermissions:0.2.1'
    compile 'com.afollestad.material-dialogs:core:0.9.3.0'
    compile project(':mediapicker')
    // JW player

    // compile 'com.longtailvideo.jwplayer:jwplayer-core:+'

    // compile 'com.longtailvideo.jwplayer:jwplayer-common:+'

    // compile 'com.longtailvideo.jwplayer:jwplaer-ima:+'

    // compile 'com.longtailvideo.jwplayer:jwplayer-chromecast:+'
    compile project(':jwplayer')
}
apply plugin: 'com.google.gms.google-services'

app/proguard-rules.pro File :

-keep class com.bumptech.glide.integration.okhttp3.OkHttpGlideModule
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions

-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-dontnote okhttp3.**

# Okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }


-dontwarn java.lang.invoke.*


-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}

# http://stackoverflow.com/questions/29679177/cardview-shadow-not-appearing-in-lollipop-after-obfuscate-with-proguard/29698051
-keep class android.support.v7.widget.RoundRectDrawable { *; }

# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# RxJava 0.21

-keep class rx.schedulers.Schedulers {
    public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
    public <methods>;
}
-keep class rx.schedulers.TestScheduler {
    public <methods>;
}
-keep class rx.schedulers.Schedulers {
    public static ** test();
}


# Glide specific rules #
# https://github.com/bumptech/glide

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}

# JWPlayer
-keepattributes *longtailvideo*
-keep class com.longtailvideo.*{ *; }
-dontwarn com.longtailvideo.*
-keepclasseswithmembernames class * {
    native <methods>;
}

-dontwarn com.googlecode.mp4parser.authoring.tracks.mjpeg.OneJpegPerIframe

-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn com.z.picasso.**
-keepclasseswithmembernames class * {
    native <methods>;
}

After Try to get Release APK It shows some warnings Bellow Message Warning :

Information:Gradle tasks [:app:assembleRelease]
Warning:Ignoring Android API artifact com.google.android:android:1.6_r2 for debug
Warning:Ignoring Android API artifact com.google.android:android:1.6_r2 for release
Warning:Ignoring Android API artifact com.google.android:android:1.6_r2 for buildTypes
Warning:com.longtailvideo.jwplayer.cast.b: can't find superclass or interface com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer
Warning:com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar$2: can't find referenced method 'android.widget.TextView access$000(com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar)' in program class com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar
Warning:com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar$2: can't find enclosing method 'void setTextProgressAlign()' in program class com.akexorcist.roundcornerprogressbar.TextRoundCornerProgressBar
Warning:com.longtailvideo.jwplayer.JWPlayerFragment: can't find referenced field 'int media_route_menu_item' in program class com.longtailvideo.jwplayer.R$id
Warning:com.longtailvideo.jwplayer.JWPlayerFragment: can't find referenced field 'int ccl_media_route_menu_title' in program class com.longtailvideo.jwplayer.R$string
Warning:com.longtailvideo.jwplayer.JWPlayerSupportFragment: can't find referenced field 'int media_route_menu_item' in program class com.longtailvideo.jwplayer.R$id
Warning:com.longtailvideo.jwplayer.JWPlayerSupportFragment: can't find referenced field 'int ccl_media_route_menu_title' in program class com.longtailvideo.jwplayer.R$string
Warning:com.longtailvideo.jwplayer.cast.CastEvents$DeviceListener: can't find referenced class com.google.android.gms.cast.CastDevice
Warning:com.longtailvideo.jwplayer.cast.CastManager: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.CastManager: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException
Warning:com.longtailvideo.jwplayer.cast.CastManager: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException
Warning:com.longtailvideo.jwplayer.cast.CastManager: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.gms.cast.CastDevice
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.gms.cast.MediaStatus
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.gms.cast.RemoteMediaPlayer
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.gms.cast.CastDevice
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.gms.cast.MediaStatus
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.gms.cast.RemoteMediaPlayer
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.a: can't find referenced class com.google.android.gms.cast.CastDevice
Warning:com.longtailvideo.jwplayer.cast.b: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer
Warning:com.longtailvideo.jwplayer.cast.b: can't find referenced class com.google.android.gms.cast.ApplicationMetadata
Warning:com.longtailvideo.jwplayer.cast.b: can't find referenced class com.google.android.gms.cast.TextTrackStyle
Warning:com.longtailvideo.jwplayer.cast.b: can't find referenced class com.google.android.gms.cast.MediaQueueItem
Warning:com.longtailvideo.jwplayer.cast.b: can't find referenced class com.google.android.gms.cast.CastDevice
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.gms.cast.MediaInfo
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.gms.cast.MediaTrack
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.gms.cast.RemoteMediaPlayer
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.gms.cast.MediaInfo
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.gms.cast.MediaTrack
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.gms.cast.RemoteMediaPlayer
Warning:com.longtailvideo.jwplayer.cast.c: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.c$a: can't find referenced class com.google.android.gms.cast.MediaStatus
Warning:com.longtailvideo.jwplayer.cast.c$a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.c$a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException
Warning:com.longtailvideo.jwplayer.cast.c$a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException
Warning:com.longtailvideo.jwplayer.cast.c$a: can't find referenced class com.google.android.gms.cast.MediaStatus
Warning:com.longtailvideo.jwplayer.cast.c$a: can't find referenced class com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaInfo
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaInfo$Builder
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaMetadata
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaTrack
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaTrack$Builder
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.common.images.WebImage
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaInfo$Builder
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaMetadata
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaTrack$Builder
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.common.images.WebImage
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaInfo
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaMetadata
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaInfo
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaMetadata
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaTrack
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaInfo
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaMetadata
Warning:com.longtailvideo.jwplayer.cast.d: can't find referenced class com.google.android.gms.cast.MediaTrack
Warning:rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.ConcurrentCircularArrayQueue: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.ConcurrentSequencedCircularArrayQueue: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.MpmcArrayQueueConsumerField: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.MpmcArrayQueueProducerField: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.MpscLinkedQueue: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.SpmcArrayQueueConsumerField: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.SpmcArrayQueueProducerField: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.SpscArrayQueue: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.SpscUnboundedArrayQueue: can't find referenced class sun.misc.Unsafe
Warning:rx.internal.util.unsafe.UnsafeAccess: can't find referenced class sun.misc.Unsafe
Warning:there were 147 unresolved references to classes or interfaces.
Warning:there were 6 unresolved references to program class members.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
Information:BUILD FAILED
Information:Total time: 3.217 secs
Information:1 error
Information:81 warnings
Information:See complete output in console

MutableList use as keyword

`when(msg?.what){
    MESSAGE_GET_LIST -> {
     if (msg.obj != null && msg.obj is MutableList<*>){
                        list = msg.obj as MutableList<BaseIncomeBean>
                        ` 

when I received a message and want to use it ,I must covert to MutableList use as keyword

Finally build my project and appear following warning

Warning:(51, 40) Unchecked cast: Any! to MutableList<BaseIncomeBean>

How do I fix this warning?

Consider the code below:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView =  (ImageView) convertView; //here

        if (imageView == null) {
            imageView = (ImageView) inflater.inflate(R.layout.item_gallery_image, parent, false);
        }
        ImageLoader.getInstance().displayImage(IMAGE_URLS[position], imageView, options);
        return imageView;
    }

Findbugs plugin from Android Studio is complaining about the first line from the method getview, it says:

Unchecked/unconfirmed cast This cast is unchecked, and not all instances of the type casted from can be cast to the type it is being cast to. Check that your program logic ensures that this cast will not fail.

Any ideas of how do I resolve this issue?

I have 2 classes ( EF Models ) exposed as odata entityset,

public class Customer
{
    public int Id { get; set; }

    public string Name { get; set; }

    [Required]
    public Address Address { get; set; }
}

public class Address
{
    public int Id { get; set; }

    public string State { get; set; }

    public string City { get; set; }
}

When I query for Customers in specific city using odata filter like

http://localhost:62680/odata/Customers?$expand=Address&$filter=Address/City eq 'Chennai'

It generates the following inefficient sql with City filtering done in WHERE Clause,

SELECT 
    [Extent1].[Id] AS [Id], 
    N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C1], 
    [Extent1].[Name] AS [Name], 
    [Extent1].[Address_Id] AS [Address_Id], 
    cast(1 as bit) AS [C2], 
    N'Address' AS [C3], 
    N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C4], 
    [Extent2].[Id] AS [Id1], 
    [Extent2].[State] AS [State], 
    [Extent2].[City] AS [City], 
    cast(1 as bit) AS [C5], 
    cast(0 as bit) AS [C6]
    FROM  [dbo].[Customers] AS [Extent1]
    INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[Address_Id] = [Extent2].[Id]
    WHERE ([Extent2].[City] = @p__linq__0)

Ideally, it should have generated query with And clause in Inner join for filtering the city like the one below

    SELECT 
        [Extent1].[Id] AS [Id], 
        N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C1], 
        [Extent1].[Name] AS [Name], 
        [Extent1].[Address_Id] AS [Address_Id], 
        cast(1 as bit) AS [C2], 
        N'Address' AS [C3], 
        N'462b9c81-0a7a-4015-aa08-bcdb2ec067ec' AS [C4], 
        [Extent2].[Id] AS [Id1], 
        [Extent2].[State] AS [State], 
        [Extent2].[City] AS [City], 
        cast(1 as bit) AS [C5], 
        cast(0 as bit) AS [C6]
        FROM  [dbo].[Customers] AS [Extent1]
        INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[Address_Id] = [Extent2].[Id] 
and ([Extent2].[City] = @p__linq__0)

Is there any way I can influence the query generation process for Odata request. Please advise.

Library Info :

Microsoft.AspNet.OData : 7.0.1 Entity Framework : 6.2

I don't understand why I'm having this errors and how to solve them, on the following code in mine MainActivity file. I've searched on Google but I can't relate the solutions to mine code. I have also passed -Xlint:unchecked to javac, but can't get any wiser either.

I'm pretty new to Android and Java programming and trying to solve any highlights in mine code.

Thanks in advance.

Unchecked assignment: 'java.util.ArrayList' to 'java.util.ArrayList' less... (Ctrl+F1) Signals places where an unchecked warning is issued by the compiler, for example:

void f(HashMap map) { map.put("key", "value"); } Hint: Pass -Xlint:unchecked to javac to get more details.


Unchecked call to 'ArrayList(Collection)' as a member of raw type 'java.util.ArrayList' less... (Ctrl+F1) Signals places where an unchecked warning is issued by the compiler, for example:

void f(HashMap map) { map.put("key", "value"); } Hint: Pass -Xlint:unchecked to javac to get more details.


private void readItems() {
    File filesDir = getFilesDir();
    File todoFile = new File(filesDir, "todo.txt");
    try {
        items = new ArrayList<>(FileUtils.readLines(todoFile));
    } catch (IOException e) {
        items = new ArrayList<>();
    }
}

To restate the question: Which is better, one central detailed comment, or several smaller "sprinkles"?

Bear with me while I set up the scene:

I've got this function for popping a value from a queue implementation:

int queue_pop(queue *list, void **pValue);

If you're familiar with C, you understand that calling this function like this:

struct foo *pFoo;
int rc;
rc = queue_pop(g_FooList, &pFoo);

you get this:

gcc: warning-incompatible pointer type passing 'foo **' to parameter of type 'void **'

Now, as it happens, calling this function like this is perfectly safe; the function never addresses the dereferenced pointer as anything other than a void*, and memory allocation and copying is done based strictly on the element size, which is defined on any given queue. But, to avoid the warnings, I call it like this:

rc = queue_pop(g_FooList, (void**)&pFoo);

which is also not strictly portable in C, but again, in this case, is perfectly safe. But, since casting function arguments is almost NEVER necessary in C, and is in fact almost ALWAYS covering up an error, I document the first call of this type in every function like this:

/* Explicit cast - see comments on queue_pop function in queue.c */
rc = queue_pop(g_FooList, (void**)&pFoo);

That way, anyone reading the code can open the queue.c file and read a detailed explanation of why this is OK, and not to worry about it. And, since they won't do that, at least they know that it was done on purpose, and there is a reason.

The question arises because somone suggested that I get rid of the cast -- since it is so unusual -- and just call the function with the concrete pointer type. Then suppress the warning with a #pragma push at the top of the source file, and put a detailed comment on the pragma explaining the suppression. Since the codebase is eventually going to be open-source, and the source code comments (versus header file comments) are therefore going to have a wider audience than normal, it's more organized that way.

Aside from the fact that I'm not a big fan of suppressing warnings in the first place (except for some of the sillier MSVC ones), it's been my exprerience that:

  • A) people will not read
  • B) if you want someone to read something, you better stick it right in front of their eyeballs
  • C) see A

Now, the comments tag says it's for questions about "Best Practices", but I realize this one might tend a bit too far toward "opiniony". If that's the case, just hang a few downvotes on it, and I'll delete the question.

EDIT I saw this question, but it looks like a general mosh about whether or not to use comments at all. That's not the issue here: I'm definitely going to use some kind of comment.

I have an issue compiling idevicerestore under kali linux. I believe I have all of the dependencies installed correctly. I get the following:

> make  all-recursive
make[1]: Entering directory `/root/idevicerestore'
Making all in src
make[2]: Entering directory `/root/idevicerestore/src'
  CC     idevicerestore-dfu.o
dfu.c: In function ‘dfu_get_cpid’:
dfu.c:243:48: warning: initialization makes pointer from integer without a cast [enabled by default]
dfu.c:248:21: error: dereferencing pointer to incomplete type
dfu.c: In function ‘dfu_get_ecid’:
dfu.c:260:48: warning: initialization makes pointer from integer without a cast [enabled by default]
dfu.c:265:21: error: dereferencing pointer to incomplete type
dfu.c: In function ‘dfu_is_image4_supported’:
dfu.c:278:48: warning: initialization makes pointer from integer without a cast [enabled by default]
dfu.c:283:21: error: dereferencing pointer to incomplete type
dfu.c: In function ‘dfu_get_ap_nonce’:
dfu.c:293:48: warning: initialization makes pointer from integer without a cast [enabled by default]
dfu.c:298:17: error: dereferencing pointer to incomplete type
dfu.c:298:42: error: dereferencing pointer to incomplete type
dfu.c:299:46: error: dereferencing pointer to incomplete type
dfu.c:303:28: error: dereferencing pointer to incomplete type
dfu.c:304:29: error: dereferencing pointer to incomplete type
dfu.c: In function ‘dfu_get_sep_nonce’:
dfu.c:317:48: warning: initialization makes pointer from integer without a cast [enabled by default]
dfu.c:322:17: error: dereferencing pointer to incomplete type
dfu.c:322:43: error: dereferencing pointer to incomplete type
dfu.c:323:46: error: dereferencing pointer to incomplete type
dfu.c:327:28: error: dereferencing pointer to incomplete type
dfu.c:328:29: error: dereferencing pointer to incomplete type
make[2]: *** [idevicerestore-dfu.o] Error 1
make[2]: Leaving directory `/root/idevicerestore/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/idevicerestore'
make: *** [all] Error 2
>

Any ideas?

I create a class and I'm getting an warning message when I try to cast an object as AnyObject. The warning is: " Conditional cast from 'Any' to 'AnyObject' always succeeds " How can I remove this warning from my file ?

Here is my code:

class WebServices
{
    class func getRequest( urlString: String, successBlock :@escaping (_ response :AnyObject)->Void, errorMsg:@escaping (_ errorMessage :String)->Void )
    {
        var request = URLRequest(url: URL(string: urlString)!)
        request.httpMethod = "GET"

        let task = URLSession.shared.dataTask(with: request) { (data, urlResponse, error) in

            DispatchQueue.main.async {
                if(error == nil)
                {
                    do {
// Here is the warning 
                        let responseJSON = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? AnyObject 
                        guard let _ = responseJSON else {
                            errorMsg("Some error has been occurred!")
                            return
                        }
                        successBlock(responseJSON!)
                    }
                    catch
                    {
                        errorMsg("Some error has been occurred!")
                    }
                }
                else
                {
                    errorMsg(error!.localizedDescription)
                }
            }
        }
        task.resume()
    }
}

Thank you guys for your time if you are reading this !