`

Why would a static inner interface be used in Java?

阅读更多

Q:
I have just found a static inner interface in our code-base.

  1. class Foo {
  2.     public static interface Bar {
  3.         /* snip */
  4.     }
  5.     /* snip */
  6. }
复制代码

I have never seen this before. The original developer is out of reach. Therefore I have to ask SO:

What are the semantics behind a static interface? What would change, if I remove the static? Why would anyone do this?

A:
An inner interface has to be static in order to be accessed. The interface isn't associated with instances of the class, but with the class itself, so it would be accessed with Foo.Bar, like so:

  1. public class Baz implements Foo.Bar {
  2.    ...
  3. }
复制代码

In most ways, this isn't different from a static inner class.

分享到:
评论

相关推荐

    Continuous Enterprise Development in Java

    Learn a use-case approach for developing Java enterprise applications in a continuously test-driven fashion. With this hands-on guide, authors and JBoss project leaders Andrew Lee Rubinger and Aslak ...

    Modern Java In Action 2019

    Put simply, the new features in Java 8 along with the (less-obvious) changes in Java 9 are the biggest change to Java in the 21 years since Java 1.0 was released. Nothing has been taken away, so all ...

    coreJava240问与答面试题

    1) what are static blocks and static initalizers in Java ? .......................................................... 9 2) How to call one constructor from the other constructor ? .......................

    Android代码-static-maps-api

    Fluent and clean Java interface for Google Static Maps API. > DEMO APK Why? Because using Google Play Services to show a Google Map may be overkill, or simply because Google Play Services are not ...

    building_reactive_microservices_in_java

    This report is for developers and architects interested in developing microservices and distributed applications. It does not explain the basics of distributed systems, but instead focuses on the ...

    Learning.Reactive.Programming.With.Java.8

    If you are a Java developer that knows how to write software and would like to learn how to apply your existing skills to reactive programming, this book is for you. In Detail Whether you are a Java ...

    concurrency in java

    simply more things that can go wrong in a concurrent program than in a sequential one. So, why do we bother with concurrency? Threads are an inescapable feature of the Java language, and they can ...

    深入java虚拟机(inside the java virtual machine)

    Inner Float: A Java float Reveals its Inner Nature The Floating Point Opcodes Circle of Squares: A Simulation On the CD-ROM The Resources Page 15 Objects and Arrays A Refresher on Objects and ...

    smali2java.jar

    Dex2jar is a good utility and smali2java is another good utility. You can use dex2jar or smali2java or both. Technical questions Does smali2java check smali syntax? All of syntax checks are based on...

    FAQs in Quantitative Finance.pdf

    19. What is a utility function and how is it used? 90 20. What is Brownian Motion and what are its uses in finance? 94 21. What is Jensen’s Inequality and what is its role in finance? 97 22. What is ...

    Beginning Cryptography With Java 带源码

    Beginning Cryptography with Java While cryptography can still be a controversial topic in the programming community, Java has weathered that storm and provides a rich set of APIs that allow you, the ...

    mastering.java

    Chapter 6: Java Interview Questions – lastly, I have provided you with a comprehensive list of questions that you could be asked in an interview for a Java programming job. I also provide the answers...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    More complex inline functions may also be put in a .h file for the convenience of the implementer and callers, though if this makes the .h file too unwieldy you can instead put that code in a ...

    java傻瓜编程系列英文版kindle

    INTRODUCTION. 1 How to Use This Book. 1 Conventions Used in This Book....What You Don’t Have to Read....Foolish Assumptions....How This Book Is Organized ....Part 1: Getting ...The words in a Java program. 45

    java面试宝典

    194、In a architecture pattern like MVC, it is mandatory that Servlet should be the controller, why not JSP? 46 195、Why JSP is used as View part of MVC ? 46 196、Can a database connection pool be ...

    Pragmatic Unit Testing in Java 8 with JUnit(PACKT,2015)

    Pragmatic Unit Testing in Java 8 With JUnit steps you through all the important unit testing topics. If you've never written a unit test, you'll see screen shots from Eclipse, IntelliJ IDEA, and ...

    pro spring batch

    scalable, distributed batch processing system using open-source frameworks Pro Spring Batch gives concrete examples of how each piece of functionality is used and why it would be used in a real-world...

    Java2核心技术卷I+卷2:基础知识(第8版) 代码

    Java As a Programming Platform 2 The Java “White Paper” Buzzwords 2 Java Applets and the Internet 7 A Short History of Java 9 Common Misconceptions about Java 11 Chapter 2: The Java ...

    the java programming language fourth editionArnoldGoslingHolmes06

    Developers around the world have used previous editions to quickly gain a deep understanding of the Java programming language, its design goals, and how to use it most effectively in real-world ...

    java课件下载

    0.2 What Is a Computer? 0.3 Networks, the Internet, the World Wide Web 0.4 Why Study Programming? 0.5 Programming Languages 0.6 Why Study Java? 0.7 What Is Object-Oriented Programming?

Global site tag (gtag.js) - Google Analytics