Questions tagged [static-class]

In object oriented programming a static class is a class whose members must be accessed without an instance of the class. Its members must be created as static.

In object oriented programming a static class is a class whose members must be accessed without an instance of the class. Its members must be created as static.

90 questions
480
votes
14 answers

Why are you not able to declare a class as static in Java?

Why are you not able to declare a class as static in Java?
Mariselvam
  • 4,915
  • 3
  • 20
  • 10
28
votes
6 answers

Inner class in interface vs in class

What is the difference between these two innerclass declarations? Also comment on advantages/disadvantages? case A: class within a class. public class Levels { static public class Items { public String value; public String path; …
Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
19
votes
3 answers

what are the main differences between a Java/C# static class?

In C# a static class is a class that, in addition to not supporting inheritance, can have any kind of type member a "normal" class can have except instance members. Not so sure how static classes work in java, but based on the limited amount of java…
John Smith
  • 4,416
  • 7
  • 41
  • 56
13
votes
4 answers

How to wrap a static class in a non-static instance object (dynamically)

I have an interesting problem. I need to wrap static classes dynamically. I.e. return a non-static instance to my callers. e.g.: public object CreateInstance(string className) { Type t = assembly.GetType(className); if (IsStatic(t)) { …
gatapia
  • 3,574
  • 4
  • 40
  • 48
12
votes
4 answers

Bloch Effective Java - favor static classes over nonstatic - how many instances?

I want to know how many instances of a static member class can be created by the enclosing class. I assume one only, but then the following extract from Bloch doesn't make sense to me. Quoting Joshua Bloch's Effective Java - Item 22*: Favor static…
Adam
  • 5,215
  • 5
  • 51
  • 90
11
votes
5 answers

Static Class VS Private Constructor

Today, I have been reading about static class and private constructor. Static Class - We cannot create an instance on the static class. we cannot inherit the static class. Only single instance is generated. Private Constructor - We cannot create an…
KiddoDeveloper
  • 568
  • 2
  • 11
  • 34
11
votes
2 answers

Access or get Autofac Container inside a static class

I need to get or access to my IoC container in a static class. This is my (simplified) scenario: I register dependencies for ASP .net Web Api in a Startup class (but also I do this for MVC or WCF. I have a DependecyResolver project, but for…
8
votes
3 answers

Inner static class in Java

What is benefit of using an inner static class? Where should I prefer it over other options? And how is its memory allocated?
Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112
5
votes
1 answer

Initialize static class implicitly

is it possible to initialize a static class on app start up "automatically"? By automatically I mean without the need of referencing a property. The reason I want to be able to do this for is that I'd like to automatically theme an app on start…
5
votes
2 answers

PHP Static Class or Namespace

I'm wanting to gauge people's opinions on the use of static classes instead of namespaces. I come from a C++ background and am quite fond of its syntax and how it lets you structure code. I recently decided I needed to group my code into logical…
user1520427
  • 1,345
  • 1
  • 15
  • 27
4
votes
3 answers

Are static classes the right way?

I am developing an application in Java, which manages a database of bank's loans. I have some expierience in application developing and I have a question that might be silly but it is something I always talk about since I've been learning developing…
Stefanos Kargas
  • 10,547
  • 22
  • 76
  • 101
4
votes
0 answers

How do I share lots of unrelated methods between different classes without creating a "god namespace/static class"?

A "God Namespace" is the (uncommon) term for an (anti?)pattern analogous to the "God Object", when you stuff a metric ton of stuff (mostly methods/functions) that is not related or not closely related to each other into one huge namespace/static…
user3079266
4
votes
3 answers

Using "this" keyword inside nested static class java

I have a class say A, and a static nested class say B. public class A { public static class B { B(Temp x) { x.reg(this); // need to pass the nested class reference. } } } Is the above code correct? Can we use…
Karthik207
  • 493
  • 9
  • 27
4
votes
1 answer

Load static class in appdomain

I'm met with a big problem in C# AppDomain. I need to load a static class in a .dll file and execute its method: When I try to load them by Assembly.LoadFrom("XXXXX") // (XXXXX is the full path of dll) the .dll will not be unload automatically or…
Wenchao You
  • 43
  • 1
  • 3
4
votes
2 answers

This Handler class should be static or leaks might occur (com.test.test3.ui.MainActivity.1)

I am new to android and i try to develop a system but when i finish code the handler show this warning below show the code after I edit, the handler in event ontounch show the warning handler cannot be resolved. I try putting // to ignore the…
1
2 3 4 5 6