Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Is this a method call or variable declaration ???

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is this a method call or variable declaration ???

    I am looking at some ksoap-2-android then I saw this
    http://stackoverflow.com/questions/3...oid-with-https

    Is this a method call or a variable declaration ?

    private TrustManager[] trustAllCerts = new TrustManager[]{
    }


    private TrustManager[] trustAllCerts = new TrustManager[]{
    new X509TrustManager() {
    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    return null;
    }
    public void checkClientTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }
    public void checkServerTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }
    }
    };


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is this a method call or variable declaration ???


  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Is this a method call or variable declaration ???

    It defines an array.

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is this a method call or variable declaration ???

    My confusion is this:
    private TrustManager[] trustAllCerts = new TrustManager[]{
    new X509TrustManager() {
    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    return null;
    }
    public void checkClientTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }
    public void checkServerTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }
    }
    };

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is this a method call or variable declaration ???

    ups I mean this:
    private TrustManager[] trustAllCerts = new TrustManager[]{
    new X509TrustManager() {
    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    return null;
    }

    How this should be understood ?
    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    return null;

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Is this a method call or variable declaration ???

    public java.security.cert.X509Certificate[] getAcceptedIssuers()
    That looks like a method definition.

    Your code would be more readable if you would Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    Last edited by Norm; March 11th, 2012 at 10:33 AM.

  7. #7
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is this a method call or variable declaration ???

    Norm: it is not my code I am trying to understand
    soap - KSOAP 2 Android with HTTPS - Stack Overflow
    when you click on the link you will see this
    private TrustManager[] trustAllCerts = new TrustManager[]{
    new X509TrustManager() {
    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    return null;
    }
    public void checkClientTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }
    public void checkServerTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }
    }
    };
    I abosolutely don't understand and Array with so many method call, the is idea of doing this ?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Is this a method call or variable declaration ???

    TrustManager[] trustAllCerts = new TrustManager[]
    That code defines an array named trustAllCerts of type TrustManager
    If you had properly formatted the code you would see.

    private TrustManager[] trustAllCerts = new TrustManager[]{  //define array
           new X509TrustManager() {  // Define a class as element in the array
                     // add  methods to the class
                     public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                           return null;
                     }
                     public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                     }
                     public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
                    }
           }  // end of class
    }; //end of array definition

  9. #9
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is this a method call or variable declaration ???

    Norm:
    Tks for your time

Similar Threads

  1. Replies: 4
    Last Post: February 26th, 2012, 05:36 PM
  2. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM
  3. Variable declaration placement
    By 2nickpick in forum Java Theory & Questions
    Replies: 2
    Last Post: January 22nd, 2011, 11:34 AM
  4. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM
  5. Use variable in array declaration statement
    By thedolphin13 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 24th, 2010, 03:42 PM