Not epoxy; at least, not alone. I use the classic barbed wedges for securing a hammer head.
For epoxy composite handles, I fill the gap with epoxy and drive in as many slivers of fiberglass as I can. I use the rods because the glass fibers are aligned axially. One source was fiberglass fence posts, Another would be fiberglass rods. I ise a knife to split them into narrow slivers and drive them into the uncured epoxy, as many as I can. My favorite hammer was a 3 lb. engineer's hammer with a fiberglass cored handle. The epoxy that came with the bedding kit pulverized under the beating of use. When I finally replaced the OEM system with the above, it lasted for several decades. It finally met it's demise when I ran over it with a Brush Hog mower. (actually cut the handle in two)
I used the system for setting a fiberglass handle into an 8 lb. splitting maul after the original fixing system failed, maybe 40 years ago. Another hammer with the same system has remained intact for several decades as well.
For wood, I use the barbed wedges avilable from a hardware store. I have also forged my own wedges for use on a straight peen hammer that I forged and handle that I made from a hickory tree that I cut. That was in 1978 and it is still going strong.
I have used nails for a quick fix but it is not really satisfactory. They tend to come loose. Horseshoe nails tend to work a little better as they are tapered. In driving a classic wedge, I will drive it on a diagonal so the wood expands in both directions. One good trick is to dry the wooden handle in an oven. This will shrink the wood. As the wood picks up moisture after assembly, it will swell and tighten the assembly. Blacksmiths used to soak their hammers overnight to swell the wood for the next day's work.