`

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.

分享到:
评论

相关推荐

    java面试题英文版及其答案

    7. What is a Java package, and why is it used?Answer: A Java package is a namespace mechanism that organizes related classes and interfaces into modules. Packages help avoid naming conflicts, provide ...

    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 ...

    Module 2 Unit 4 What would you like to be测试题2.doc

    这篇测试题主要涵盖了小学六年级Module 2 Unit 4 "What would you like to be" 的核心内容,涉及了与职业相关的词汇、短语翻译以及选择题,旨在帮助学生理解和掌握与未来职业愿望和不同职业特点相关的基本英语知识。...

    深入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...

    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 ...

    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?

    Cracking the PM Interview

    How would you launch a video rental service in India? This book will teach you how to answer these questions and more., Cracking the PM Interview is a comprehensive book about landing a product ...

Global site tag (gtag.js) - Google Analytics